You are on page 1of 6

Cognizant Trainees C-Programming Mock Test

1. What would be the output oI the Iollowing program?
void main() ¦
int a ÷ -1 , b ÷ 5;
clrscr();
if(++a && b++)
printf("True");
else
printf("False");
printf("ºd ºd",a,b);
getch();
]
a) True -1 5 b) False -1 5 c) False 0 5 d) True 0 5
Answer: (c)

2. What would be the output oI the Iollowing program?
main( ) ¦
int a ÷ 5, b, c ;
b ÷ a ÷ 15 ;
c ÷ a < 15 ;
printf ( "\na ÷ ºd b ÷ ºd c ÷ ºd", a, b, c ) ;
]
(a) 15 15 15 (b) 5 garbage vale 15 (c) 15 15 0 (d) 0 0 0

Answer: (c)
3. Which explanation will be apt Ior the error in this program :
main( ) ¦
float a ÷ 12.25, b ÷ 12.52 ;
if ( a ÷ b )
printf ( "\n a and b are equal" ) ;
]
(a) 12.25 is not equal to 12.52
(b) Instead oI equal operator assignment operator is used.
(c) Syntax error in iI condition part.
(d) Compile time error
Answer: b
4. Point out the errors, iI any, in the Iollowing program:
main( ) ¦
int x ÷ 10, y ÷ 15 ;
if ( x º 2 ÷ y º 3 )
printf ( "\n What should I print?" ) ;
]
(a) L value required error (b) R value required error
(c) No error (d) Run time error
Answer: a
5. What would be the output oI the Iollowing program?
main( ) ¦
int a÷ 0;int b ÷ 20;char x ÷1;char y ÷10;
if(a,b,x,y)
printf("hello");
]
a) hello b) No output C) Run Time Error d) Syntax Error
Answer: a
6. What would be the output oI the Iollowing program?
void main() ¦
static int i÷5;
if(--i) ¦ main();
printf("ºd ",i);
]
}
a) 1 1 1 1 b) 0 0 0 0 c) 5 5 5 5 d) Compile time Error
Answer: b
7. What would be the output oI the Iollowing program?
main() ¦ int i÷10,j÷20;
j ÷ i, j?(i,j)?i:j:j;
printf("ºd ºd",i,j);
}
a) 20 20 b) 10 20 c) 20 10 d) 10 10
Answer d)
8. What would be the output oI the Iollowing program?
void main() ¦
int i;
clrscr();
for(;;);
printf("Inside the loop");
getch();
]
Answer: b
a) Inside the loop will be printed Ior inIinite times. b) Blank screen and hanging
c) Run Time Error d) Syntax Error

9. What would be the output oI the Iollowing program?
void main() ¦
float i÷10.1;
clrscr();
switch(i) ¦
case 10:
printf("Ten");
break;
default:
printf("Other than ten");
]
getch();
]
Answer: b
a) Other than ten
b) Switch statements can be applied only to integral types.
c) Ten
d) Run Time Error


10. What would be the output oI the Iollowing program?
void main()¦
char i÷99;
clrscr();
switch(i) ¦
case 'c':
printf("char c");
break;
case 99:
printf("int 99");
break;
default:
printf("Other than c or 99");
]
getch();
]
a) Other than c or 99
b) char c
c) int 99
d) case values duplication
Answer: d
11. What would be the output oI the Iollowing program?

main() ¦
float i÷1.5;
switch(i)
¦
case 1: printf("1");
case 2: printf("2");
default : printf("0");
]
]

Answer: b
a) Compiler Error
b) Switch statements can be applied only to integral types.
c) 1 2 0
d) Run Time Error

12. What is the output oI the Iollowing program?
main() ¦
int a¡10];
printf(~ºd ºd¨,a¡-1], a¡12]); ]
a) 0 0 b) 1 0 c) Garbage values d) -1 12
Answer: c
13. What is the output oI the Iollowing program? Assume that the beginning address oI array
is 6008.
main()¦
int a¡5];
printf(~ºu ºu¨, &a¡-1], &a¡6]); ]

a) 6008 6018 b) -1 6
c) Garbage values d) 6006 6020
Answer: d
14. What is the output oI the Iollowing?
main() ¦ char str1¡ ] ÷ ~abc¨;
char str2¡ ] ÷ ~abc¨;
if(str1÷ ÷ str2)
printf(~true¨);
else
printf(~false¨);
]
a) Ialse b) true
c) Syntax error d) logic error
Answer: a
15. What is the output oI the Iollowing?
main()
¦ char str1¡ ] ÷ ~abc¨;
char str2¡ ] ÷ ~abcd¨;
printf(~ºd¨, strcmp(str1,str2))
]
a) 1 b) 100
c) 0 d) -100
Answer: d
16. What is the output oI the program?
main() ¦
char arr¡]÷ ~ hello\0\0\0\0\0¨;
char arr1¡]÷ ~ hello\n\n\n\n\n¨;
clrscr();
printf(~ Values of arr ºd\tºd\n¨,sizeof (arr),strlen(arr));
printf(~Values of arr1 ºd\tºd¨,sizeof (arr1),strlen(arr1));
]
'alues oI arr
a) 11 5 b) 5 5 c) 5 11 d) 10 10 Answer: a
'alues oI arr1
a) 11 10 b) 5 5 c) 5 10 d) 10 10 Answer: A

17. What is the output oI the program?

void main() ¦
int a¡ ]÷¦15,16,17,18];
clrscr();
printf(~ºd¨,a¡2.9999]);
getch();
]

a) Iloat cannot be used in index b) No error
c) 17 d) all the above
Answer (c)
18. What would be the output oI the Iollowing program?

int a¡ ]÷¦1,2,4];
int b¡3]÷¦1,2,3];
main() ¦
printf(~ºd¨,a¡b¡1]]);
]

a) 4 b) CompilerError
c) 2 d) garbage value

Answer (a)
19. Find the output Ior the Iollowing C program
void main(void) ¦
char names¡6]¡7]÷¦"Raja","Vignesh","Pradeep","Vijay","Nishanth"];
printf("ºs ºs ºs", &names, names, names¡0]);
]

a) Garbage value Garbage value Garbage value b) Raja Raja Raja
c) Raja Raja Garbage value d) Compiler error
Answer b
20. What will be the output?
void main() ¦
char arr|8|÷¦'S','A',''','R','I','Y','A'};
char *p;
p÷(char *)(arr¹2)|2|;
clrscr();
printI("°c",p);
getch();
}

f% ' b) R c) I d) Y
Answer :c

94:/-0904:95:9419014435747.7747   .3  57391 /   < < .4/2.38.2 ..78.3  39 .   .78.2 .3/..33 .7747 3807.3   39.2 2.94:/-0904:95:9419014435747.3903  . /01.9  . / 42509207747 3807-  .4/2. 04.3  14.44:95:9 #:3%207747/ $39.7.7  1 .  < 3807- . .2 .   57391 04  < .  .. 39- .2 2.94:/-0904:95:9419014435747.  .   /    3807/   . . .94:/-0904:95:9419014435747.7  89.4/2. #:3%207747/ $39.80    57391 %03    -70.   .9. 38/090445-057390/147313909208 .3 39        57391 //    < .3  89.39 1  2.7003..7  147   57391 38/090445  09.94:/-0904:95:9419014435747.    .:9   57391  9079.

:08/:5.$9.3.80.3  14..:9  57391  9079.4/2.7  89.9508       .   -70.. %03 / #:3%207747    .3-0.  < 3807- .47  < 09.< 09..    .47 ..89. 39 / . .3-0.$9.7. .7 .7.9508  ..94:/-0904:95:9419014435747.89.9020398.8057391   .8057391   /01.  9079.80 .3903 .. 425077747 .78.9020398..  < .94:/-0904:95:9419014435747.80  57391 39   -70.550/43943907.3..   57391 .   ..9  89...2 .3  .943 3807/  .  9079.:957391    < <  3807- ..550/43943907. /01.2  2..

1.3  .07747 3807.77( 0433333    ...-./  57391 / 897.:08/     3807/  .  .77  57391 '.:08/   3807.7897( .   .2  2.80   < . .3    .288:209.0.   1 897897   57391 97:0   080 57391 1.98904:95:9419014435747.77   < .7    57391 '.3   . ( 57391 // .3  39.98904:95:9419014435747.25 897 897  < .77/9/3 8041 .   .//708841.( < .  .3  39.78. 8   2..77 89703 .98904:95:941901443  2. $39.98904:95:941905747.:0841.. .-.7-.:0841.   .7..07747/ 4.80.  .7.( <  .-.. .7897( .77( 04      ..98904:95:941901443  2.7-.   .7897( .7897( . ( .77/9/ 8041 .   / #:3%207747   ..  /    3807/  .-..0.990-0333.97:0 .  .( 57391 ::  .77 89703 . .2 2. (  .77.

.208((#.208 3.#.7-...  /   3807   .77 .77( $  ' #    <   .   .  .3  57391 / .(  < 39-(  < 2..:0841../005 '. '308 !7. / .3     39.73.3 .78. 8..7-.   3/904:95:91479014435747...7..98904:95:941905747. #.425077747 . / .7-.78.94:/-0904:95:9419014435747. 5  . .4/   .90.   <  .407747 .9.2   39.#.:0/ 4250707747 3807-  .. /   3807.7 5   5 .-4.2 .4/2.-((  <  .3    .. .0.:0  3807 . .7-.7    57391 .7    57391 / .(   <   .0..0.. .:0.:0841..0.. 14.208 (  <  .0 3807 .#.77  (   .. (    09.77 ..:0.0.4/2.2    . '.'.7 .3349-0:80/33/0.39< 57391 888  3.#..9-0904:95:9  .7-.208 3.4/2..:0.

#. .    < 09.  f% '. /  3807.