0% found this document useful (0 votes)
215 views

C Questions

1) The document contains 25 multiple choice questions about C programming concepts such as loops, operators, pointers, arrays, strings, memory allocation, variable scope, and declarations vs definitions. 2) Many questions test understanding of operator precedence, pointer arithmetic, array indexing, and string manipulation. Correct answers require analyzing sample code snippets and determining their output. 3) Other questions cover concepts like memory allocation/deallocation, variable scope, and the difference between a variable declaration and definition in C. The right answers demonstrate a strong grasp of fundamental C programming principles.

Uploaded by

Sella Thambi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views

C Questions

1) The document contains 25 multiple choice questions about C programming concepts such as loops, operators, pointers, arrays, strings, memory allocation, variable scope, and declarations vs definitions. 2) Many questions test understanding of operator precedence, pointer arithmetic, array indexing, and string manipulation. Correct answers require analyzing sample code snippets and determining their output. 3) Other questions cover concepts like memory allocation/deallocation, variable scope, and the difference between a variable declaration and definition in C. The right answers demonstrate a strong grasp of fundamental C programming principles.

Uploaded by

Sella Thambi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

C APTITUDE: 1)Which of the following options correctly relates / and % (a)b =(a/b) * b + a%b (b)a = (a/b) * b + a%b (c)b

= (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.

You might also like