Name: Student Id: Section: Signature
Name: Student Id: Section: Signature
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
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);
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 "); }