0% found this document useful (0 votes)
82 views

Name: Student Id: Section: Signature

The document provides instructions for an exam with 40 multiple choice questions worth a total of 100 points. It reminds students to correctly code their student ID and exam type on the answer sheet. The default return type of the main function is int.

Uploaded by

Mehmet Subaşı
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Name: Student Id: Section: Signature

The document provides instructions for an exam with 40 multiple choice questions worth a total of 100 points. It reminds students to correctly code their student ID and exam type on the answer sheet. The default return type of the main function is int.

Uploaded by

Mehmet Subaşı
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

80 Minutes CENG 230 Midterm Exam 29.04.

2014 – 17:40
There are 40 questions (each 2.5 points) for a total of 100 points. Exam Type: A
All questions are multiple choice, no points will be lost for wrong answers.
Do not forget to code your student ID and exam type correctly to the answer sheet. Otherwise, your answers will not be graded.
Assume that all necessary libraries were added properly (by using "include" statements).
Default return type of the “main” function is “int”. Assume that the statement “return 0;” is added to programs if necessary.
Name: Student ID: Section: Signature:
AAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAA

1) What is the output of the following program? 8) What is the output?


main() main()
{ int x=1, y=5, z=11; { int i=0,n=5;
x += y++ + --z / 2 * 4; if (!n>5 && 1>=++i) ++n;
printf("%d", x); } printf("%d %d",i,n); }
a) 0 0 b) 0 5 c) 1 5 d) 0 6 e) 1 6
a) 7 b) 25 c) 26 d) 27 e) 29
9) What would be the output of the following program?
2) What is the output of the following program? int h(int a,int b)
main() { if (a>b) {a=-a; return b;}
{ double x; else {b=-b; return a;} }
x = 10 / 3 * 2;
printf("%.1f", x); } main()
a) 1.0 b) 1.67 c) 6.0 d) 6.67 e) 7.0 { printf("%d",h(h(4,h(3,6)),h(h(5,1),2))); }

3) What is the output of the following program? a) -1 b) 1 c) -5 d) -6 e) 6


main()
{ int a=3, b=4, c=5; 10) What will the following program print?
a = -a+(c+b*(c+a)/c-b/a)*a-b/2; main()
printf("%d", a); } { int i=5, j=10, k=15, m=0;
a) 17 b) 67 c) 40 d) 19 e) 25 while (i<=10)
while (j>=9)
while (k>10)
4) Which of the following is not a built-in C type? { i+=2; j--; k--; m++;}
printf("%d\n",m); }
a) void b) string c) char d) float e) long a) 4 b) 5 c) 6 d) 7 e) 8

11) What is the output of the below program?


5) What would be the output of the following program? main()
{ int year=2012;
main()
if ((year%4==0)&&(year%100!=0||year%400==0))
{ float x,y;
printf("%d is a leap year.\n",year);
x=5/3;
else
y=(float)(5/3);
printf("%d is not a leap year.\n",year); }
printf("%.3f %.3f",x,y); }
a) 1.000 1.000 b) 1.000 1.667 c) 1.667 1.667 a) is a leap year. b) is not a leap year.
d) 2.000 1.667 e) 1.000 2.000 c) 2012 is a leap year. d) 2012 is not a leap year.
e) Compile-time error
6) What would be the output of the following program?
main()
12) What is the output of the below program?
{ if (2>3) main()
{ printf("A"); { int i=0, j=1, k=3, l=4, m=5;
if (5>3) printf("B"); } if (k=--j&&(m=l-k))
else printf("C"); printf("m=%d k=%d", m, k);
printf("D"); } else
printf("m=%d k=%d", m, k); }
a) B b) BD c) AB d) ABD e) CD a) m=1 k=1 b) m=1 k=0 c) m=5 k=3
d) m=5 k=1 e) m=5 k=0
7) Variables a,b,c have different values. Which value is output
among these values? 13) Which of the following loops should be substituted in place
if (a>b) { if (b>c) printf("%d",b); } of ---(1)--- in order to display “*” 4 times ?
else if (c>b) printf("%d",b); (The output should be: ****)
else if (a>c) printf("%d",a); main()
else printf("%d",c); { int i=1, j=6;
a) the smallest b) the biggest c) the middle d) value of b, always ---(1)--- }
e) the smallest or the biggest, depending on values of a and c
a) for (;i<=j;i+=2) printf("*");
b) for (i=3;i<=j;i+=1) printf("*");
c) for (;i<=j;i+=1) printf("****");
d) for (;i<=j;i+=0) printf("**");
e) for (;i<=j;i++) printf("**");
AAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAA

14) What would be the output of the following program? 20) How many lines of output shown ?
main()
{ int x=4,y=3; main()
switch (x%y--) { int i,j;
{ case 0: printf("%d ",x); i=0;
case 1: printf("%d ",y); j=8;
default: printf("%d ",x-y); } } while((j>4) && (i=0))
{
a) 4 2 2 b) 3 2 c) 2 1 d) 2 2 e) 4 3 2 printf("%f",i);
if(j%2==0)
printf("\n");
15) Which one of the following declarations is wrong and j--; } }
causes a compile-time error?
a) int s=0/3; b) int x+=y+++3; c) float c=5,3;
d) long integer=5; e) double e=3+5.1; a) 0 b) 2 c) 4 d) 5 e) 10

16)What would be the output of the following program? 21) What is the output of the following program?

main() main()
{ int x=-2, y=4, z; { int n=1;
z = 3*(++x!=-2)+5*((y---3==0)||(x<y)&&(x>=2)); switch (++n)
printf("%d", z); } { case 0: n *= 1;
a) 3 b) 5 c) 8 d) 0 e) -2 case 1: n /= 2;break;
case 2: n += 3;
case 3: n += 2;
17) What would be the output of the following program? default: printf("**"); }
main() printf("%d", n); }
{ double TicketPrice;
char block,row;
block='C'; a) **7 b) 7 c) 0 d) ** e) **5
row='B';
TicketPrice = 5.00; 22) What would be the output of the following program?
if (block=='A')
if (row=='B') main ()
TicketPrice = 10.00; { float x=0.12378e+3;
else printf("%.1f",x); }
TicketPrice = 20.00;
printf("%5.2f", TicketPrice); }
a) 12.3 b) 123.7 c) 123.8 d) 12.4 e) 123.78
a) 5.00 b) 10.00 c) 10 d) 20.00 e) 25.00

18) What would be the output of the following program? 23) What would be the output of the following program?
main() main()
{ int x=1,y=1; { printf("%d\n",(8%3*3/5&&2*4-1)-5*2-3); }
if(x=--y) printf("M");
if(-1) printf("E");
if(3.99) printf("T"); a) -10 b) -11 c) -12 d) -13 e) -14
if(0) printf("U");
if('0') printf("CENG\n"); }

a) METUCENG b) ETCENG c) METCENG d) MET e) METU 24) Which of the following data types are wrong?
I. integer
II. double
19) What would be the output of the following program? III. real
IV. string
main() V. char
{ int i=0, j, counter1=0, counter2=0;
do
{ while(++i<=5) a) I, II, V b) II, IV c) I, III, IV
counter1++; d) Only IV e) III, IV
counter2++;
}while(i++<8);

printf("%d %d", counter1, counter2); }

a) 5 0 b) 10 2 c) 5 1 d) 5 2 e) 10 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAA

25) What would be the output of the following program? 29) What would be the output of the following program?
main() main()
{ int k,l,m=10; { int x=8,y=1;
double a,g=0; switch(x)
for (k=0;k<=m;k++) { default:
{ do case 3: x/=3;
{ a=1; case 2: x-=2;
for (l=1;l<=k;l++) case 1: y++;break;
{ a+=a*l; case 0: x--; y++; }
g=g+(k+(m-k)/a); } printf("%d %d",x,y); }
(a--)+(++g);
g++;
} while(a<0); a) 8 1 b) 1 3 c) 0 2 d) -1 3 e) 1 2
}
printf("%0.2f", g); } 30) What would be the output of the following program?
main()
a) 453.68 b) 414.86 c) 425.86 { int a,b=0,c=5,d=5,i;
a=b;
d) 436.86 e) Infinite loop c=d;
d=b;
do
26) What would be the output of the following program? { for (i=1;i<=c;i++);
main() { c+=5;
{ int i=1, b=-2, c=3, e=0, t=0; if (c>=29) break;
if (i%5!=0) printf("*"); }
if (!(b>0)||!(b*(c--))<=i) while (a<=9)
{ { a=a+4;printf("+"); b=a; ++c; }
t=1; }while(a=b); }
if (!c) a) *****+++ b) *****++ c) *+++***
i=t+(++i); d) *+++*+++*+++ e) Infinite Loop
else
b=t/(b--); }
else
c=i+(--e); 31) Given the expression in English:
printf("%d %d %d", i, b, c); } "if x and y are both not equal to z then t=7, otherwise t=5"
Which of the following is the equivalent C statement to the
a) 5 2 0 b) 1 -1 3 c) 1 0 2 expression above?
d) −2 3 −3 e) None of them a) if (x!=z&&y!=z) t=7; else t=5;
b) if ((x&&y)!=z) t=7; else t=5;
c) if (!(x=z)&&!(y = z)) then t=7; otherwise t=5;
27) What would be the output of the following program?
int var; d) if (!(x==z)%%!(y==z)) t=7; t=5;
int func(int x) e) if ((x&&y)!==z) t=7; else t=5;
{ var+=x;
return var; } 32) What is the output?
main() main()
{ int y;
{ int y=3,a=5;
y=3;
y=a==3;
y=func(y);
printf("%d %d",a,y); }
printf("%d",func(y)); }
a) 3 3 b) 5 1 c) 5 3 d) 0 5 e) 5 0
a) 3 b) 6 c) 9 d) 0 e) 12
33) What is the output?
int f1 (int x)
{ int y=2; printf("%d%d",x,y);
28) What would be the output of the following program? return x++; return ++y; }
main()
{ int y=5, x=5;
#define A x+10 printf("%d%d\n",f1(y),y); }
#define B y+5
main()
{ int x=10,y=5; a) 5255 b) 25424 c) 5555 d) 5256 e) 5552
printf("%d ",++A/2);
printf("%d",--B*2); }

a) 16 14 b) 11 19 c) 10 18 d) 11 18 e) 10 19
AAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAA

34) What will be the output of the program? 38) What will be the output of the program?
int k=1;
int add(int x) { return (x+k++); } int fun(int a, int b, int c)
int mult(int k) { return(k*=2); } { if (a<b<c)
main() printf("quot = %d\n", b-a / c-b);
{ int t = 2; else if (a<b)
add(k); printf("c-b may be zero! %d\n", b-a / c-b ); }
printf("%d %d ",t,k);
k = mult(t); main()
printf("%d %d ",k,t); } { fun(-11, 5, 3); }

a) 1 2 1 2 b) 1 2 2 1 c) 2 4 2 4
a) quot = -8
d) 2 2 4 4 e) 2 2 4 2
b) quot = 4
c) quot = 3
d) c-b may be zero! -8
35) What is wrong with the below given function definition: e) Compile-time error
deamon(int n)
{ for(; n; n--) printf("\n"); }
39) What will be the output of the program?
a) Nothing is wrong!
b) Either the function should return a value or should be float halve(int x)
declared void. { if (x%2) return (x-1)/2;
else return x/2; }
c) The type of the function is unspecified.
d) The initialization part of the for loop is missing. main()
e) You cannot change the value of a function parameter. { printf("%.1f\n", 10+halve(5)); }

a) Compile-time error
b) Run-time error
36) What will the the following program do?
c) 12.1f
main() d) 12.0
{ int x,y,z;
e) 12
for (x=1,y=2,z=3; x<10,y<5,z<10; x++,y--,z=x++)
printf("line\n"); }
40) In which of the following loops, we can be sure that △
a) print nothing. b) print 1 line. c) print 5 lines. statement will never be executed? (Assume i is of type int)
d) print 7 lines. e) go into an infinite loop. a) do △ while (i+3/4);
b) for (; i,3/4;) △
c) do △ while (i,3/4);
d) while (i+3/4) △
37) What will be the output of the above program?
main() e) for (;i+3/4;) △
{ int x=1 ;
while (x<2)
{ x++ ;
if (x==2)
{ x++ ;
break ;
printf("all "); }
printf("for "); }
printf("one "); }

a) all for one b) for one c) one


d) Nothing e) Compile-time error

You might also like