C Programming Practice Set-I
01. What is the final value of the digit?
main() { int digit; for(digit=0;digit<=9;++digit) printf("%d\n",digit); digit = 2*digit; --digit; }
1) 19
2) -1
3) 17
4) 16
02. What is the output of the following program?
#include <stdio.h> #define square(x) x*x main() { int b,c=3; b=square(c)++; printf("%d",b); }
1) 3
2) 4
3) 9
4) 16
03. If x and y are variables declared as double x=0.005, y=-0.01; What is the value of ceil(x+y) where ceil is a function to compute the ceiling of the number.
1) 1
2) 0
3) 0.005
4) 0.5
04. What will be the output of the following program?
main() { int i = 255, j=0177, k=0xa0; printf("%x %o %d",i,j,k); }
1) 255 0177 a0
2) ff 177 160
3) 255 0177 0xa0
4) error
05. In the case of ordinary int variables
1) the left most bit is reserved for sign
2) the right most bit is reserved for sign
3) no bit is reserved for sign
4) none
06. #define microprocessor command is used for defining
1) macros
2) for loop
3) symbolic constants
4) both 1 and 3
07. If i=20 and j=i<=i then
1) i=j
2) j=2i
3) j=2j
4) j=i-1
08. The minimum number of temporary variables needed to swap the contents of two variables is
1) 2
2) 1
3) 3
4) 0
09. Coercion
1) takes place across assignment operator
2) takes place if an operator has operands of different data types
3) means casting
4) both 1 and 2
10. What is the output of the following
main() { int x,y=2,z,a; x=(y*=2)+ (z=a-y); printf("%d",x); }
1) 7
2) 6
3) 8
4) error
11. Bit fields will be accommodated in a word
1) from left to right
2) from right to left
3) in a way that depends on the implementation
4) none of the above
12. The && and || operators are used to
1) combine two numeric values
2) combine two Boolean values
3) combine two float values
4) combine two double values
13. A C function can have variable parameters
1) true
2) false
3) can't say
4) none
14. Can a void pointer be used in manipulations
1) yes
2) no
3) can't say
4) none
15. Output of the following
struct abc { }; main() { printf("%d",sizeof(struct abc)); }
1) 1
2) 0
3) error
4) none
16. switch(a)
{ default: printf("A"); case 1: printf("B"); }
If a=2 then the output is
1) AB
2) A
3) B
4) error
17. Which keyword in C is used to avoid register storage
1) static
2) extern
3) volatile
4) none
18. What is the value of k in the following code?
struct ab { char a; char b; }; union abcd { int c; struct ab d; } jk; jk.d.a = 5; jk.d.b = 0; // when the value of k.c is
1) 5
2) 7
3) 0
4) 50
19. fp = fopen("abc.dat","r+"); then the contents of "abc.dat"
1) exists
2) can be modified
3) can be appended
4) all
20. What is the output of the following program
int i=7; extern int a; f(i); printf("%d %d",a,i); } int a; f(int g) { g=g+1; a=g; }
1) 7
2) 8
3) error
4) none
21. In recursion which variables are not stored on the system stack
1) static
2) local
3) global
4) both a and c
22. What is the output of the following program
int a[]={4,2,3}; int *p=a; p++; printf("%d",*p);
1) 4
2) 2
3) error
4) none
23. Can a function be passed as a parameter to another function
1) true
2) false
3) can't say
4) none
24. What is the value of c is
enum abc {a=1,b=5,c=8};
1) 6
2) 2
3) 7
4) garbage
25. char * const p = "Good" then
1) contents of p can be changed
2) "Good" can be changed
3) Both 1 and 2
4) none
26. Which of the following is the primitive data type
1) string
2) array
3) file
4) none
27. What is the output of the following program
int sum=0; for(i=-10;i++) if(i%2==0) sum=i+sum; printf("%d",sum);
1) 45
2) 40
3) 0
4) 30
28. If a=-11 and b=-3. What is the value of a%b
1) 2
2) 3
3) -2
4) -2
29. What is the output of the following program
main() { int sum=0,i; for(i=100;i>=0;i--) sum=abs(i)-sum; printf("%d",sum); }
1) 100
2) 5050
3) -5050
4) -100
30. Pick the correct statement
1) unions are like structures
2) unions contains members of different data types which share same storage area in memory
3) unions are less frequently used in program
4) all the above
31. Consider the following declaration enum colors {black,blue,green}; this represents
1) black=0,blue=1,green=2
2) color ='black' or color ='blue' or color ='green'
3) color[0]='black'
4) none
32. The library function exit() is used for exit from
1) a loop
2) a block
3) a program
4) all
33. When an array name is passed to a function, the function
1) accesses exactly the same array with the same name as the calling program
2) accesses a copy of the array passed by the program
3) both 1 and 2
4) none
34. What is the output of the following program
#define row 3 #define col 4 int a[row][col]={ 1,2,3,4,5,6,7,8,9,10,11,12}; main() { // code is incomplete, output depends on print statement }
1) 12
2) 10
3) 12,245 is a legal string constant in C
4) none
35. What is the output of the following program
main() { int a=25,*ptr,b,c; ptr=&a; b=a*30; c=*ptr; printf("%d %d %d",a,b,c); }
1) 25,25,25
2) 25,750,25
3) 25,55,55
4) none
36. What is the output of the following program
main() { char ch='A'; while(ch<'F') { switch(ch) { case 'A': case 'B': case 'C': case 'D': case 'E': ch++; case 'F': ch++; } putchar(ch); } }
1) ABCDEF
2) FG
3) EFG
4) CEG
37. Pick the correct one
1) while(0) { i=2; } 2 is assigned to i
2) do { i=2; } while(0); 2 is assigned to i
3) both 1 and 2
4) none
38. Pick the correct one
1) calloc() allocates and clears memory
2) malloc() allocates memory but does not clear memory
3) both 1 and 2
4) none
39. Pick the correct one
1) a char type has an equivalent integer interpretation so it is really special kind of short integer
2) the printf() is a macro which takes in a variable number of arguments
3) 12,245 is a legal string constant in C
4) none
40. Pick the correct one
1) the statement x=x+2 is equivalent to the statement x+=4
2) an if else statement can be replaced by a ternary operator
3) both 1 and 2
4) none
41. What is the output of the following program
extern int a; main() { printf("%d",a); } int a=50;
1) 50
2) 0
3) garbage value
4) error
42. Suppose a program is divided into 3 files f1, f2, f3 and a variable defined in f1 is to be used in files f2 and f3 then the storage class of the variable is
1) auto
2) static
3) register
4) extern
43. Examine the following program
main() { display(); display(); printf("Titanic is a ship"); } // Pick the correct answer
1) display() function returns void type data by default
2) display() function returns int type data by default
3) display() function displays a message "Titanic is a ship" and returns number of bytes displayed
4) both 2 and 3
44. What is the output of the program
main() { int i; int a[5]={10,20}; for(i=0;i<5;i++) printf("%d",a[i]); }
1) 10 20
2) 10 20 0 0 0
3) 10 20 and remaining 3 values are garbage
4) error in initialization
45. What would be the output of the program
main() { int i=4; switch(i) { default: printf("A is a upper case letter"); case 1: printf("B is a lower case letter"); case 2: printf("0-9 digits"); break; case 3: printf("Ascii value of a is 97"); } }
1) default keyword should not be on top of all cases
2) A is upper case letter B is a lower case letter
3) Wont print any message as no case is 4
4) None
46. Point out the error, if any in the following program
main() { int i; for( ; ; ) { printf("%d",i++); if(i>10) break; } }
1) the condition in the for loop is a must
2) the two semicolons should be dropped
3) the for loop should be replaced by a while loop
4) no error in the program
47. Point out the error, if any, in the following program?
main() { int i=4, j=1, k=2; switch(i) { case i: case j: case k: printf("All are same"); break; } }
1) error as no statements for first two cases
2) constant expressions required in the second and third case, we can't use i and k
3) no error in the program
4) none of the above
48. Point out the error if any, in the following program
main() { int i=1; switch(i) { case 1: printf("n Hello"); case 1: printf("n case one"); break; case 2: printf("n case two"); break; case 1+3*4: printf("n case last"); break; } }
1) the first printf() can never get executed and all statements in a switch have to belong to same case or the other
2) case label should not be an expression
3) the first printf should not exist, so error in program
4) none of the above
49. What would be the output of the following program
main() { int i=-3, j=2, k=0, m; m=++i && ++j || ++k; printf("%d %d %d",i,j,k,m); }
1) -4 2 0 1
2) -4 3 0 1
3) -2 3 0 1
4) -2 3 1 1
50. What would be the output of the following program
main() { printf("%d %d",sizeof(3.0),sizeof(3f)); }
1) 4 4
2) garbage value
3) 8 4
4) 8
51. By default any real number is treated as
1) float
2) double
3) long double
4) depends upon memory model used
52. What would be the output of the program
main() { int arr[] = {12,13,14,15,16}; printf("%d %d %d",sizeof(arr),sizeof(*arr),sizeof(arr[0])); }
1) 2 2 2
2) 10 2 2
3) 5 2 2
4) none
53. What would be the output of the following program
#include <stdio.h> main() { int a,b=5; a=b=!NULL; printf("%d",a); }
1) 1
2) 6
3) 7
4) 0
54. What would be the output of the following program
main() { int near *a; int far *b; int huge *c; printf("%d %d %d",sizeof(a),sizeof(b),sizeof(c)); }
1) 2 2 2
2) 2 2 4
3) 2 4 4
4) 4 4 4
55. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments
1) main(int argc, char *argv[])
2) main(char *argc, int argv[])
3) main(int argc, char *argv[ ])
4) none
56. What would be the output of the following program assuming that the array begins at location 1002.
main() { int a[3][4] = { 1,2,3,4,5,6,7,8,9,10,11,12}; printf("%u %u",a[0]+1, *(a[0]+1)); }
1) 1004 2
2) 1004 2
3) 1004 2 0
4) none
57. What would be the output of the following program
#include <stdio.h> main() { printf("%d",sizeof(NULL)); }
1) garbage
2) 0
3) 1
4) 2
58. Examine the following program and comment on it
main() { float *p1,l=25.5; char *p2; p1 = &l; p2 = &l; }
1) executes successfully
2) simply a warning
3) an error of suspicious pointer conversion
4) none
59. What is the output of the following program
main() { char a[]="neelesh"; char *b="neelesh"; printf("%d %d",sizeof(a),sizeof(b)); printf("%d %d",sizeof(*a),sizeof(*b)); }
1) 1 1 2 1 1
2) 10 10 1 1
3) 1 2 10 10
4) none
60. Examine the following program
main() { const int x; x=128; printf("%d",x); }
1) 128
2) error at compile time
3) error at runtime
4) none
61. Pick up the correct one from following
1) bool is a keyword in C
2) asm is a keyword in C
3) void is a keyword in C
4) none of the above
62. What would be the output of the following program
main() { int i=10,j=12,k,l,m; k = i&j; l = i || j; m = i^j; printf("%d %d %d",k,l,m); }
1) 1 4 8 6
2) 6 8 14
3) 8 14 6
4) none
63. Which of the following bitwise operator is used for masking a particular bit in a number
1) &
2) |
3) ^
4) ~
64. What is the maximum memory that we can allocate by a single call of malloc()
1) 64KB
2) 640KB
3) 256 bytes
4) infinite size
65. What would be the output of the second printf() in the following program
#include <alloc.h> main() { int *p; p=(int*)malloc(20); printf("%u",p); // suppose this prints 1314 free(p); printf("%u",p); }
1) 1314
2) 1316
3) garbage
4) error
66. What would be the output of the following program
main() { float a[]={ 1.2,4.2,3,4,5,6,7}; printf("%d",sizeof(a)/sizeof(a[0])); }
1) 1
2) 0
3) 7
4) 2
67. What would be the output of the following program
main() { char str[] = "hello"; printf("%s",str); }
1) error
2) hello
3) can't say exactly
4) none
68. Which of the following is true about "argv"
1) it is an array of character pointers
2) it is a pointer to an array of character pointers
3) you cannot use variable name other than argv
4) none
69. A C program contains the following array declaration char text[80]; and initialized with a string "Getting a seat can be a challenging". The output resulting from the printf("%-18.7s",text);
1) Getting a seat cab be a challenging
2) Getting a seat can
3) Getting
4) Getting a seat can be a C
70. In the following program, how many functions are used
#include <stdio.h> main() { printf("hello friend"); }
1) 0
2) 1
3) 2
4) all
71. What is the output of the following program
main() { char far *s1, *s2; printf("%d %d",sizeof(s1),sizeof(s2)); }
1) 2 2
2) 4 2
3) 4 4
4) 2 4
72. What would be the output of the following program
int x=40; main() { int x=20; printf("%d",x); }
1) 40
2) 20
3) 60
4) none
73. What is the output of the following program
main() { int x=40; { int x=20; printf("%d",x); } printf("%d",x); }
1) 40 40
2) 20 40
3) 40 20
4) 20 20
74. What would be the output of the following program
main() { extern int i; i=20; printf("%d",sizeof(i)); }
1) 3
2) 4
3) 2
4) varies from compiler to compiler
75. Which of the following is correct
1) a global variable has several declarations but only one definition
2) if we use extern it is a declaration and not definition
3) a function may have several declarations but only one definition
4) all
76. What is the output of the following program
main() { display(); } void display() { printf("ECET"); }
1) Donot waste time
2) ECET
3) either
4) error
77. What is the output of the following program
main() { extern int fun(float); int a; a=fun(3.14); printf("%d",a); } int fun(aa) float a; { return(int)aa; }
1) 3
2) 3.14
3) 0
4) error
78. What would be the output of the following program
main() { struct emp e={"puli"}; printf("%d %f",e.age,e.sal); }
1) 0 0.000000
2) garbage values
3) error
4) 0.0
79. What is the output of the following program
main() { int (*p) = F; (*p)(); } F() { printf("Donot waste time"); }
1) Donot waste time
2) Donot study Enjoy
3) error
4) none
80. What is the output of the following program
main() { int i=8; while() { printf("%d",i++); if(i > 10) break; } }
1) the condition in while loop is a must
2) 8 9 10 11
3) infinite loop
4) none
81. What is the output of the following program
main() { int i=1; while(i<=3) { printf("%d",i); goto america; india: printf("I"); func() { america: printf("h"); } } }
1) 1h2h3h
2) infinite loop
3) error
4) the control goes to india not america
82. What is the output of the following program
main() { int a=10; switch(a) { } printf("Always be an Indian"); }
1) Always be an Indian
2) 10
3) error
4) none
83. What is the output of the following program
main() { int a=2,b; a >= b ? b=200; printf("%d",b); }
1) 100
2) 200
3) error
4) garbage value
84. What is the output of the following program
main() { char str[]="Come on dance. This is the day to celebrate"; int a=5; printf("%40s",str); }
1) Come on dance. This is the day to celebrate
2) Come
3) Come on celebrate.
4) Error
85. What is the output of the following program
main() { static int a[20]; int i=0; a[1] = 1++; printf("%d %d",a[0],a[1]); }
1) 0 1
2) 0 0
3) 0 1 1
4) none
86. What is the output of the following program
main() { int j=3; j = ++j + ++j; printf("%d",j); }
1) 8
2) 9
3) 10
4) none
87. What is the output of the following program
main() { int j=2; printf("%d %d",++j,j++); }
1) 3 4
2) 4 3
3) 2 2
4) 4 4
88. What is the output of the following program
main() { int x=10,y=20,z=5,i; i = x<y>z; printf("%d",i); }
1) 0
2) 1
3) error
4) none
89. In the following code in which order the functions would be called a=f1(23)+f2(36)+f3( );
1) f1,f2,f3
2) f3,f2,f1
3) varies from compiler to compiler
4) none
90. What would be the output of the following program
main() { int i=-3,j=2,k=0,m; m=++i || ++j && ++k; printf("%d %d %d",i,j,k,m); }
1) -3 2 0 1
2) -2 2 0 1
3) -2 3 1 1
4) none
91. What would be the output of the following program
main() { int i=-3,j=2,k=0,m; m=++i && ++j && ++k; printf("%d %d %d",i,j,k,m); }
1) -3 2 0 1
2) -2 3 1 1
3) -2 2 0 1
4) none
92. What is the output of the following program
main() { float b=0.8; if(b < 0.8) printf("Good Morning"); else printf("Good Night"); }
1) Good Morning
2) Good Night
3) Good Afternoon
4) none
93. What is the output of the following program
main() { float b=0.8; if(b <= 0.8) printf("Good Morning"); else printf("Good Night"); }
1) Good Morning
2) Good Night
3) Good Afternoon
4) none
94. What is the output of the following program
main() { printf("%f",sqrt(36.0)); }
1) 6.0
2) 6
3) 6.000000
4) some absurd result
95. If you want to round off x, a float, to an int value. The correct way to do so is
1) y=(int)(x+0.5)
2) y=int(x+0.5)
3) y=(int)x+0.5
4) y=(int)x/(int)x+0.5
96. Which of the following is wrong
1) float type takes 4 bytes and the format specifier used for it is %f
2) double type takes 8 bytes and the format specifier used for it is %lf
3) long double type takes 10 bytes the format specifier used for it is %Lf
4) none of the above
97. What would be the output of the following program
main() { printf("%d %d",sizeof(2.13f),sizeof(2.13),sizeof(2.13f)); }
1) 4 4 4
2) 4 garbage
3) 4 8 10
4) error
98. A float occupies 4 bytes. If the hexadecimal equivalent of each of these bytes is A,B,C and D, then when this float is stored in memory these bytes get stored in this order
1) ABCD
2) DCBA
3) 0xABCD
4) none
99. What is the output of the following program
main() { int i,j=99; for(i=0;i<=row;i++) for(j=0;j<=col;j++) if(a[i][j] < k) k=a[i][j]; printf("%d",k); } // This is a fragment, assuming k and a[row][col] are defined elsewhere
1) 99
2) 12
3) 1
4) none
100. What is the output of the following program
main() { int i=1,j=99; for(i=0;i<=row;i++) for(j=0;j<=col;j++) if(a[i][j] < k) k=a[i][j]; printf("%d",k); } // This is a fragment, assuming k and a[row][col] are defined elsewhere
1) 99
2) 12
3) 1
4) none
Submit Quiz