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

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); }

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.

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); }

05. In the case of ordinary int variables

06. #define microprocessor command is used for defining

07. If i=20 and j=i<=i then

08. The minimum number of temporary variables needed to swap the contents of two variables is

09. Coercion

10. What is the output of the following

main() { int x,y=2,z,a; x=(y*=2)+ (z=a-y); printf("%d",x); }

11. Bit fields will be accommodated in a word

12. The && and || operators are used to

13. A C function can have variable parameters

14. Can a void pointer be used in manipulations

15. Output of the following

struct abc { }; main() { printf("%d",sizeof(struct abc)); }

16. switch(a)

{ default: printf("A"); case 1: printf("B"); }
If a=2 then the output is

17. Which keyword in C is used to avoid register storage

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

19. fp = fopen("abc.dat","r+"); then the contents of "abc.dat"

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

21. In recursion which variables are not stored on the system stack

22. What is the output of the following program

int a[]={4,2,3}; int *p=a; p++; printf("%d",*p);

23. Can a function be passed as a parameter to another function

24. What is the value of c is

enum abc {a=1,b=5,c=8};

25. char * const p = "Good" then

26. Which of the following is the primitive data type

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

28. If a=-11 and b=-3. What is the value of a%b

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); }

30. Pick the correct statement

31. Consider the following declaration enum colors {black,blue,green}; this represents

32. The library function exit() is used for exit from

33. When an array name is passed to a function, the function

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 }

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); }

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); } }

37. Pick the correct one

38. Pick the correct one

39. Pick the correct one

40. Pick the correct one

41. What is the output of the following program

extern int a; main() { printf("%d",a); } int a=50;

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

43. Examine the following program

main() { display(); display(); printf("Titanic is a ship"); } // Pick the correct answer

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]); }

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"); } }

46. Point out the error, if any in the following program

main() { int i; for( ; ; ) { printf("%d",i++); if(i>10) break; } }

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

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

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); }

50. What would be the output of the following program

main() { printf("%d %d",sizeof(3.0),sizeof(3f)); }

51. By default any real number is treated as

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])); }

53. What would be the output of the following program

#include <stdio.h> main() { int a,b=5; a=b=!NULL; printf("%d",a); }

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)); }

55. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments

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)); }

57. What would be the output of the following program

#include <stdio.h> main() { printf("%d",sizeof(NULL)); }

58. Examine the following program and comment on it

main() { float *p1,l=25.5; char *p2; p1 = &l; p2 = &l; }

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)); }

60. Examine the following program

main() { const int x; x=128; printf("%d",x); }

61. Pick up the correct one from following

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); }

63. Which of the following bitwise operator is used for masking a particular bit in a number

64. What is the maximum memory that we can allocate by a single call of malloc()

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); }

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])); }

67. What would be the output of the following program

main() { char str[] = "hello"; printf("%s",str); }

68. Which of the following is true about "argv"

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

70. In the following program, how many functions are used

#include <stdio.h> main() { printf("hello friend"); }

71. What is the output of the following program

main() { char far *s1, *s2; printf("%d %d",sizeof(s1),sizeof(s2)); }

72. What would be the output of the following program

int x=40; main() { int x=20; printf("%d",x); }

73. What is the output of the following program

main() { int x=40; { int x=20; printf("%d",x); } printf("%d",x); }

74. What would be the output of the following program

main() { extern int i; i=20; printf("%d",sizeof(i)); }

75. Which of the following is correct

76. What is the output of the following program

main() { display(); } void display() { printf("ECET"); }

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

78. What would be the output of the following program

main() { struct emp e={"puli"}; printf("%d %f",e.age,e.sal); }

79. What is the output of the following program

main() { int (*p) = F; (*p)(); } F() { printf("Donot waste time"); }

80. What is the output of the following program

main() { int i=8; while() { printf("%d",i++); if(i > 10) break; } }

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"); } } }

82. What is the output of the following program

main() { int a=10; switch(a) { } printf("Always be an Indian"); }

83. What is the output of the following program

main() { int a=2,b; a >= b ? b=200; printf("%d",b); }

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); }

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]); }

86. What is the output of the following program

main() { int j=3; j = ++j + ++j; printf("%d",j); }

87. What is the output of the following program

main() { int j=2; printf("%d %d",++j,j++); }

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); }

89. In the following code in which order the functions would be called a=f1(23)+f2(36)+f3( );

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); }

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); }

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"); }

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"); }

94. What is the output of the following program

main() { printf("%f",sqrt(36.0)); }

95. If you want to round off x, a float, to an int value. The correct way to do so is

96. Which of the following is wrong

97. What would be the output of the following program

main() { printf("%d %d",sizeof(2.13f),sizeof(2.13),sizeof(2.13f)); }

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

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

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