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

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

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
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
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
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
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
8. What would be the output oI the Iollowing program?
void main() ¦
int i;
clrscr();
for(;;);
printf("Inside the loop");
getch();
]
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();
]
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
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");
]
]

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
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
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
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
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
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

19. Find the output Ior the Iollowing C program
void main(void) ¦
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
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