C Questions
C Questions
= (a%b) * b + a/b 2)The following loop for(putchar('c');putchar('a');putchar('r')) putchar('t'); (a)outputs catratratrat..... (b)syntax error
(c)catrat
3) What will be the output of the following program : void main() { printf("%d",printf("Hi!")*printf("Bye")); } (a)ByeHi!6 (b)Hi!Bye9 4) What will be the output of the following program : int main() { int main=7; { printf("%d",main); return main; } printf("Bye"); } (a)Compile-Time Error (b)Run-Time Error 5)What will be the output of the following program : void main() { int val=5; void *ptr; *(int *)ptr=5; val=ptr; printf("%d %d",*(int *)val,*(int *)ptr); } (a)Compile-Time Error (b)Unpredictable 6) What will be the output of the following program : void main() { int val=2; val = - --val- val--- --val; printf("%d",val); } (a)Compile-Time Error (b)3
(c)Hi!Bye
(d)None of these
(c)7Bye
(d)7
(c)5 5
(d)None of these
(c)-1
(d)0
7)What will be the output of the following program : void main() { if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int)) printf("Testing"); printf("OK"); } (a)No Output (b)OK (c)Testing (d)TestingOK 8)What will be the output of the following program : void main() { int a=1,b=2,c=3,d=4,e; if (e=(a & b | c ^ d)) printf("%d",e); } (a)0 (b)7 9) What will be the output of the following program : auto int a=5; void main() { printf("%d",a); } (a)Compile-Time error (b)Run-Time error 10)What will be the output of the following program : void main() { auto int a=5; printf("%d",a); } (a)Compile-Time error (b)Run-Time error 11) What will be the output of the following program : void main() { for (;printf("");); } (a)Compile-Time error (b)Executes ONLY once INFINITELY (d)None of these 12)What will be the output of the following program : void main() { int i; for (;(i=4)?(i-4):i++;) printf("%d",i); } (a)Compile-Time error (b)4
(c)3
(d)No Output
(c)5
(d)Unpredictable
(c)5
(d)Unpredictable
(c)Executes
(c)Infinite Loop
(d)No Output
13)What will be the output of the following program : void main() { int (*a)[5]; printf("%d %d",sizeof(*a),sizeof(a)); } (a)Compile-Time Error (b)2 5 14)What will be the output of the following program : void main() { int a[]={1,2,3,4,5,6}; int *ptr=a+2; printf("%d %d",--*ptr+1,1+*--ptr); } (a)Compile-Time Error (b)1 2 15)What will be the output of the following program : void main() { int a=50; const int* const ptr=&a; printf("%d %d",*ptr++,(*ptr)++); } (a)Compile-Time Error (b)51 51 16) What will be the output of the following program : void main() { int val=77; const int *ptr1=&val; int const *ptr2=ptr1; printf("%d %d %d",--val,(*ptr1)++,*ptr2); } (a)Compile-Time Error (b)77 78 77 (c)76 77 77 17)What will be the output of the following program : void main() { int val=50; const int *ptr1=&val; int const *ptr2=ptr1; printf("%d %d %d",++val,*ptr1,*ptr2); *(int *)ptr1=98; printf("\n%d %d %d",++val,*ptr1,*ptr2); } (a)Compile-Time Error (b)51 50 50 18) What will be the output of the following program : void main()
(c)5 2
(d)None of these
(c)2 3
(d)1 3
(c)51 50
(d)None of these
(d)77 77 77
(c)Run-Time Error
(d)None of these
{ int a=5u,*b,**c,***d,****e; b=&a; c=&b; d=&c; e=&d; printf("%u %u %u %u",*b-5,**c-11,***d-6,65535+****e); } (a)Compile-Time Error (b)0 65530 65535 4 (c)0 65530 65535 65539 19) int z,x=5,y=-10,a=4,b=2; z= x++ - --y * b / a; What number will z in the sample code above contain? (a) 5 (b) 6 (c) 10 (d) 11 (e) 12
(d)0 -6 -1 -2
20)With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed? (a)unalloc() (b) dropmem() (c) dealloc() (d) release() (e) free() 21)void *ptr; myStruct myArray[10]; ptr = myArray; Which of the following is the correct way to increment the variable "ptr"? (a) ptr = ptr + sizeof(myStruct); (b) ++(int*)ptr; (c) ptr = ptr + sizeof(myArray); (d) increment(ptr); (e) ptr = ptr + sizeof(ptr); 22)char* myFunc (char *ptr) { ptr += 3; return (ptr); }
int main() { char *x, *y; x = "HELLO"; y = myFunc (x); printf ("y = %s \n", y); return 0; } What will print when the sample code above is executed? (a) y = HELLO (b) y = ELLO (c) y = LLO (d) y = LO [Ans] (e) x = O 23)int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain? (a)3 (b)5 (c)7 (d)9 (e)11 24)"My salary was increased by 15%!" Select the statement which will EXACTLY reproduce the line of text above.
(a) printf("\"My salary was increased by 15/%\!\"\n"); (b) printf("My salary was increased by 15%!\n"); (c)printf("My salary was increased by 15'%'!\n"); (d)printf("\"My salary was increased by 15%%!\"\n"); (e)printf("\"My salary was increased by 15'%'!\"\n"); 25) What is a difference between a declaration and a definition of a variable? (a)Both can occur multiple times, but a declaration must occur first. (b)There is no difference between them. (c)A definition occurs once, but a declaration may occur many times. (d)A declaration occurs once, but a definition may occur many times. (e)Both can occur multiple times, but a definition must occur first.