C/C MCQ Quiz Hub

Computer Science

Choose a topic to test your knowledge and improve your C/C skills

1. What is the output of this C code? void foo(const int *); int main() { const int i = 10; printf("%d ", i); foo(&i); printf("%d", i); } void foo(const int *i) { *i = 20; }




2. Comment on the output of this C code? int main() { const int i = 10; int *ptr = &i; *ptr = 20; printf("%d ", i); return 0; }




3. What is the output of this C code? int main() { j = 10; printf("%d ", j++); return 0; }




4. Does this compile without error? int main() { for (int k = 0; k < 10; k++); return 0; }




5. Does this compile without error? int main() { int k; { int k; for (k = 0; k < 10; k++); } }




6. Which of the following declaration is not supported by C?




7. Which of the following format identifier can never be used for the variable var? int main() { char *var = "Advanced Training in C by AllIndiaExams.com"; }




8. Which of the following is not a pointer declaration?




9. What is the output of this C code? void main() { int k = 4; float k = 4; printf("%d", k) }




10. Which is false ?




11. A variable declared in a function can be used in main?




12. The name of the variable used in one function cannot be used in another function?




13. What is the output of this C code? int main() { char *p = NULL; char *q = 0; if (p) printf(" p "); else printf("nullp"); if (q) printf("q "); else printf(" nullq "); }




14. What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%d ", (int)*p); return 0; }




15. What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%f ", *(float*)p); return 0; }




16. What is the output of this C code? int *f(); int main() { int *p = f(); printf("%d ", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; }




17. What is the output of this C code? int *f(); int main() { int *p = f(); printf("%d ", *p); } int *f() { int j = 10; return &j; }




18. What is the output of this C code? int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d/n", *ptr, a); }




19. Comment on the following? const int *ptr;




20. Which is an indirection operator among the following?




21. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?




22. What is the output of this C code? int x = 0; void main() { int *ptr = &x; printf("%p ", ptr); x++; printf("%p ", ptr); }




23. What is the output of this C code? int x = 0; void main() { int *const ptr = &x; printf("%p ", ptr); ptr++; printf("%p ", ptr); }




24. What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%p ", ptr); ptr++; printf("%p ", ptr); }




25. What is the output of this C code? void main() { int x = 0; int *ptr = &5; printf("%p ", ptr); }




26. What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%d ", *ptr); }




27. What is the output of this C code? void foo(int*); int main() { int i = 10; foo((&i)++); } void foo(int *p) { printf("%d ", *p); }




28. What is the output of this C code? void foo(int*); int main() { int i = 10, *p = &i; foo(p++); } void foo(int *p) { printf("%d ", *p); }




29. What is the output of this C code? void foo(float *); int main() { int i = 10, *p = &i; foo(&i); } void foo(float *p) { printf("%f ", *p); }




30. What is the output of this C code? int main() { int i = 97, *p = &i; foo(&i); printf("%d ", *p); } void foo(int *p) { int j = 2; p = &j; printf("%d ", *p); }




31. What is the output of this C code? int main() { int i = 97, *p = &i; foo(&p); printf("%d ", *p); return 0; } void foo(int **p) { int j = 2; *p = &j; printf("%d ", **p); }




32. What is the output of this C code? int main() { int i = 10; int *p = &i; foo(&p); printf("%d ", *p); printf("%d ", *p); } void foo(int **const p) { int j = 11; *p = &j; printf("%d ", **p); }




33. What is the output of the code below? int main() { int i = 10; int *const p = &i; foo(&p); printf("%d ", *p); } void foo(int **p) { int j = 11; *p = &j; printf("%d ", **p); }




34. Which of the following are correct syntaxes to send an array as a parameter to function: A. func(&array);




35. What is the output of this C code? void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d ", k, *p, **m); }




36. What is the output of this C code? void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d ", k, *p, **p); }




37. What is the output of this C code? void main() { int k = 5; int *p = &k; int **m = &p; **m = 6; printf("%d ", k); }




38. What is the output of this C code? void main() { int a[3] = {1, 2, 3}; int *p = a; int *r = &p; printf("%d", (**r));




39. What is the output of this C code? void main() { int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); }




40. How many number of pointer (*) does C have against a pointer variable declaration?




41. What is the output of this C code? int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c; int **sptr = &ptr1; //-Ref *sptr = ptr2; }




42. What substitution should be made to //-Ref such that ptr1 points to variable C? int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a; int **sptr = &ptr1; //-Ref }




43. Which of the following declaration throw run-time error?




44. Comment on the output of this C code? int main() { int a = 10; int **c -= &&a; }




45. The function ____ obtains block of memory dynamically.




46. void * malloc(size_t n) returns:




47. calloc() returns a storage that is initialized to.




48. In function free(p), p is a:




49. What is the output of this C code? void main() { char *p = calloc(100, 1); p = "welcome"; printf("%s ", p); }




50. Memory allocation using malloc() is done in?




51. Why do we write (int *) before malloc? int *ip = (int *)malloc(sizeof(int));




52. Which one is used during memory deallocation in C?




53. Which of the following will return a result most quickly for searching a given key?




54. On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to?




55. calloc initialises memory with all bits set to zero.




56. C99 standard guarantees uniqueness of ____ characters for internal names.




57. . C99 standard guarantess uniqueness of _____ characters for external names.




58. Which of the following is not a valid variable name declaration?




59. Variable names beginning with underscore is not encouraged. Why?




60. All keywords in C are in?




61. Variable name resolving (number of significant characters for uniqueness of variable) depends on?




62. Which of the following is not a valid C variable name?




63. Which of the following is true for variable names in C?




64. Which is valid C expression?




65. What is the output of this C code? int main() { printf("Hello World! %d ", x); return 0; }




66. What is the output of this C code? int main() { int y = 10000; int y = 34; printf("Hello World! %d ", y); return 0;




67. What will happen if the below program is executed? int main() { int main = 3; printf("%d", main); return 0; }




68. What is the problem in following variable declaration? float 3Bedroom-Hall-Kitchen?;




69. Which of the following cannot be a variable name in C?




70. Which of the following cannot be a variable name in C?