Professional Documents
Culture Documents
2015 – 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 mark 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:
1) What is the output of the following program? 5) How many times CENG will be printed?
14) What is the output of the following program? 20) What is the output of the following program?
int f(int a)
{ a = a * a; main()
printf("%d ", a);
{ int i=3,j=2, b=1, c=2;
return a; }
b= b + j + (++c) + (--i);
printf("%d", b); }
main()
{ int a = 4;
printf("%d ", a); a) 8 b) 9 c) 7 d) 0 e) 6
printf("%d ", f(a));
printf("%d ", a); } 21) What is the output of the following program?
a) 4 16 4 4 b) 4 4 16 4 c) 4 16 16 16 main()
{ int a = 10, b = 11;
d) 4 16 16 4 e) 4 16 4 16
int c = (a < b)? a : b;
printf("%d", ++c); }
15) How many times the “ *” character is printed?
main()
{ int i,j; a) 10 b) 9 c) 11 d) 12 e) 13
for (i=0; i<10; i++)
for (j=0; j<=3; j++) 22) What is the output of the following program?
printf("*"); }
int fun(int i)
{ return (i++); }
a) 13 b) 30 c) 33 d) 40 e) 44 main()
{ int i; i = fun(10);
printf("%d\n", --i); }
a) 0 b) 1 c) 2 d) 3 main()
e) Run-time Error because y and z is not printed { int x=1,y=1;
printf("%d ",func(x++,++y));
24) What is the output of the following program? printf("%d",func(y++,x++)); }
main()
{ int x; a) 4 3 b) 4 4 c) 2 4 d) 4 6 e) 2 6
switch(x=3.2)
{ case 0: printf("zero\n"); break; 29) What is the output of the following program?
case 1: printf("one\n"); break;
case 2: printf("two\n"); break; main(){
case 3: printf("three\n"); break;
int i,j,sum=0,time=01;
default: printf("default\n"); break; } } for(i=1;i<6;i++){
j=0;
a) zero b) one c) three time*=i;
d) default e) Compile-time Error while(j<i){sum+=j;j++;}
sum+=time;}
25) What is the output of the following program? printf("%d %d",sum,time);
}
float power(float val, unsigned pow) a) 20 173 b) 120 173 c) 173 20 d) 20 120 e) 173 120
{ float ret_val=1.0, j;
unsigned i; 30) What is the output of the following program?
for(i=0; i<pow; i++)
ret_val *= val+val; main()
return(ret_val);
{ int x=0,i;
j=7; for(i=0;i<5;i++)
return j; } { switch(i)
{ case 0: x++;
main() case 1: x*=x;break;
{ float x; case 2: x+=x;
x=power(3,2); default: x--; } }
printf("%.2f",x); } printf("%d",x); }
26) What is the output of the following program? 31) How many times 1 will be printed on the screen?
main()
{ int a=1; main()
if (a!=!a) { int i=1;
if (a==1) for(i=16;i!=0;i-=2)
{ a++; } { switch(i%4)
else if (++a) ++a; { case 0: printf("0");
else a--; case 1: printf("1"); break;
else --a-1; case 2: printf("2"); break;
a--; case 3: printf("3"); } } }
printf("%d",a); }
a) Compile-time Error b) 0 times c) 1 time d) 4 times e) 8 times
a) -1 b) 1 c) 2 d) 3 e) Compile-time Error
27) Which of the following expressions equivalent to the this 32) What is the output of the following program?
boolean expression: !(A<5 && B !=C)
main()
a) A>5 || B !=C b) A>=5 && B ==C c) !(A<5) || (B !=C) { int n1=0,n2=1;
if( n1 && (n2-- % n1 == 0))
d) A>=5 || B ==C e) A<5 && B ==C
printf("C");
printf("%d",n2); }
a) Compile-time Error b) C1
c) Run-time Error(Divide by Zero)
d) C0 e) 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
33) What is the output of the following program? 39) What is the output of the following program?
main()
{ int i=75;
for(; i>0;)
{ --i;
i/=3;
printf("%d ",i);
if(i==5) break; } }
a) 24 7 2 0 b) Run-time error c)25 8 2 0
d) Compile-time error e) 25 5
main()
{ int i;
char k='n', n='k';
for(i=1; i<=k-'k'; i++)
{ if(i==('n'-n)) k='k'-i;
n=n+1; }
printf("%c%c",k,n); }
a) km b) kn c) im d) in e) nk
main()
{ int i, j, k=1, m=1;
for(i=1; i<=3; i++)
{ for(j=i; j>=1; --j)
{ m=m*(-1);
for(k=i-j+1; k<=i; k++)
m++; } }
printf("%d",m); }
a) -3 b) -2 c) 0 d) 2 e) 3