You are on page 1of 5

QUIZ

1. What would be the output of the following program? main() { char str1[] = Hello; char str2[] = Hello; If (str1 = = str2) Printf (\n Equal); Else } a. Equal b. Not equal c. Error d. None of the above 2. If you want the value of a variable to persist between different function calls a. static b. register c. extern d. auto 3. Regarding the scope of the varibles;identify the incorrect statement: a. automatic variables are automatically initialized to 0 b. static variables are automatically initialized to 0 c. the address of a register variable is not accessible d. static variables cannot be initialized with any expression 4.

Main must be written as a. The first function in the program b. Second function in the program c. Last function in the program d. Any where in the program

5.

#include <stdio.h> void func() { int x = 0; static int y = 0; x++; y++; printf( "%d -- %d\n", x, y ); } int main() { Func();

func (); return 0; } What will the code above print when it is executed? a. 1-- 1 1 --1 b. 1 -- 1 1 -- 2 c. 1 -- 1 2 -- 1 d. 1 -- 0 1 -- 0 6. What would be the output of the following program ? Main ( ) { int a [5] = {2,3}; printf ( \n%d %d %d, a[2], a[3], a[4] ) ; } a. Garbage values b. 2, 3, 3 c. 3, 2, 2 d. 0, 0, 0 7. What would be the output of the following programs ? Main ( ) { int arr [ ] = { 12, 13, 14,15, 16}; print f ( \ n %d %d %d, size of (arr), size of (* arr ), size of (arr[o] ) ) ; } a. 2, 2, 2 b. 10, 2, 2 c. 2, 10, 2 d. 4, 2 8. Suppose the array begins at address 1500, then what would be output of the following program ? Main ( ) { int a [ ] = { 4,5,1,2,3,7}; print f ( %d , size of (a) ) ; } a. 15, 12 b. 12 c. 1500 d. 2 9. To read multiple words from the key board ____ input function is used.

a. scanf() b. read() c. gets() d. getchar() 10. char x[] = hello; printf( %d, x[0] x[1] ); What is the output? a. garbage value b. error c. 0 d. 3 Which of the following does not lead to run time errors? a. Dividing by zero b. Square root of the negative number c. Logarithm of zero d. Exceeding the system dependent limits main() { printf("%d", out); } int out=100; a. Compiler error b. 100 c. out

11.

12.

d. no value
13. The conditional expression for the following information is given as 4 x + 100 for x > 40 Salary = 300 for x = 40 4.5 x + 150 for x > 40 a. salary b. salary c. salary d. salary 14. = (x! = 40) ? ((x < 40) ? (4 * x + 100) : (4.5 * x + 150)) : 300; = (x! = 40) ? (4 * x + 100) : (x < 40) ? (4.5 * x + 150)) : 300; = (x! = 40) ? (4 * x + 100) : 300 : (x < 40) ? (4.5 * x + 150) = (x! = 40) ? (4 * x + 100) : 300 : (x < 40) ? (4.5 * x + 150) : 300

main() { int i=08 ; printf(%d,i); } Output of the i is a. 0 b. 8 c. error d. 08987. We want to round off x, a float, to an int value. The correct way to do so would be

a. y = (int) (x + 0.5); b. y = int ( x + 0.5); c. y = (*int) x + 0.5; d. y = (int) ( (int) x + 0.5) 15.
int a[50000]; main(){ } [ A ] garbage [ B ] ans array too large [ C ] run time error [ D ] none

Answer : B
16.
static int i = 6; extern i; main() { printf("%d",i); }

[ A ] complie error [ B ] run time eror [ C ] 6 [ D ] garbageAnswer : C


17. int z; int x = 5; int y = -10; int a = 4; int b = 2; z = x++ - --y * b /a; What number will z in the sample code above contains a. 5 b. 6 c. 10 d. 11 18. The infinite loop using for loop is a. for (test condition ; ; ) { } b. for (test condition ; ; ) { } c. for ( ; ;expression 3 ) { } d. for ( ; ;test condition ) { } 19. Point out the error if any in the for loop Main ( ) { int i = 1; for ( ;;) { printf (%d, i++) ;

if ( i > 10 ) break; } } a. b. c. d. e. The condition in the for loop is a must The two semicolons should be dropped The for loop should be replaced by a while loop No error

20.

Consider the following program main() { int a[5]={1,3,6,7,0}; int *b; b=&a[2]; } The value of b[-1] is a. 1 b. 3 c. -6 d. none

You might also like