Home
MCQS
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; }
Compile time error
10 20
Undefined value
10
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; }
Compile time errorB. C. D. 10
Compile time warning and printf displays 20
Undefined behaviour
10
3. What is the output of this C code? int main() { j = 10; printf("%d ", j++); return 0; }
10
11
Compile time error
0
4. Does this compile without error? int main() { for (int k = 0; k < 10; k++); return 0; }
Yes
No
Depends on the C standard implemented by compilers
None of the mentioned
5. Does this compile without error? int main() { int k; { int k; for (k = 0; k < 10; k++); } }
Yes
no
Depends on the compiler
Depends on the C standard implemented by compilers
6. Which of the following declaration is not supported by C?
String str
char *str;
float str = 3e2
Both (a) and (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"; }
%f
%d
%c
%s
8. Which of the following is not a pointer declaration?
char a[10];
char a[] = {&#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;4&#039;};
char *str;
char a;
9. What is the output of this C code? void main() { int k = 4; float k = 4; printf("%d", k) }
Compile time error
4
4.0000000
4.4
10. Which is false ?
A variable defined once can be defined again with different scope
A single variable cannot be defined with two different types in the same scope
A variable must be declared and defined at the same time
A variable refers to a location in memory
11. A variable declared in a function can be used in main?
True
False
True if it is declared static
None of the mentioned
12. The name of the variable used in one function cannot be used in another function?
True
False
May be
None of the mentioned
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 "); }
nullp nullq
Depends on the compiler
x nullq where x can be p or nullp depending on the value of NULL
p q
14. What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%d ", (int)*p); return 0; }
Compile time error
Segmentation fault/runtime crash
10
Undefined behaviour
15. What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%f ", *(float*)p); return 0; }
Compile time error
Undefined behaviour
10
0.000000
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; }
10
Compile time error
Segmentation fault/runtime crash since pointer to local variable is returned
Undefined behaviour
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; }
10
Compile time error
Segmentation fault/runtime crash
Undefined behaviour
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); }
10,10
10,11
11,10
11,11
19. Comment on the following? const int *ptr;
You cannot change the value pointed by ptr
You cannot change the pointer ptr itselfC.
Both (a) and (b)
You can change the pointer as well as the value pointed by it
20. Which is an indirection operator among the following?
&amp;
*
-&gt;
.
21. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?
int *ptr = &amp;a;
int *ptr = &amp;a &quot;“ &amp;a;
int *ptr = a &quot;“ a;
All of the mentioned
22. What is the output of this C code? int x = 0; void main() { int *ptr = &x; printf("%p ", ptr); x++; printf("%p ", ptr); }
Same address
Different address
Compile time error
Varies
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); }
0 1
Compile time error
0xbfd605e8 0xbfd605ec
0xbfd605e8 0xbfd605e8
24. What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%p ", ptr); ptr++; printf("%p ", ptr); }
0xbfd605e8 0xbfd605ec
0xbfd605e8 0cbfd60520
0xbfd605e8 0xbfd605e9
Run time error
25. What is the output of this C code? void main() { int x = 0; int *ptr = &5; printf("%p ", ptr); }
5
Address of 5
Nothing
Compile time error
26. What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%d ", *ptr); }
Address of x
Junk value
0
Run time error
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); }
10
Some garbage value
Compile time error
Segmentation fault/code crash
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); }
10
Some garbage value
Compile time error
Segmentation fault
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); }
10.000000
0.000000
Compile time error
Undefined behaviour
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); }
2 97
2 2
Compile time error
Segmentation fault/code crash
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); }
2 2
2 97
Undefined behaviour
Segmentation fault/code crash
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); }
11 11 11
11 11 Undefined-value
Compile time error
Segmentation fault/code-crash
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); }
11 11
Undefined behaviour
Compile time erro
Segmentation fault/code-crash
34. Which of the following are correct syntaxes to send an array as a parameter to function: A. func(&array);
func(array);
func(array);
func(*array);
func(array[size]);
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); }
5 5 5
5 5 junk value
5 junk value
Run time error
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); }
5 5 5
5 5 junk value
5 junk value
Compile time error
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); }
5
Compile time error
6
Junk
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));
1
Compile time error
Address of a
Junk value
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); }
Different address is printed
1
Same address is printed
1 1
40. How many number of pointer (*) does C have against a pointer variable declaration?
7
127
255
No limits
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; }
ptr1 points to aB. ptr1 points to bC. sptr points to ptr2D. None of the mentioned.
ptr1 points to b
sptr points to ptr2
None of the mentioned.
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 }
*sptr = &amp;c;
**sptr = &amp;c;
*ptr1 = &amp;c;
None of the mentioned
43. Which of the following declaration throw run-time error?
int **c = &amp;c;
int **c = &amp;*c;
int **c = **c
None of the mentioned
44. Comment on the output of this C code? int main() { int a = 10; int **c -= &&a; }
You cannot apply any arithmetic operand to a pointer.
We don&#039;t have address of an address operator
Both (a) and (b)
None of the mentioned
45. The function ____ obtains block of memory dynamically.
calloc
malloc
Both a &amp; b
free
46. void * malloc(size_t n) returns:
Pointer to n bytes of uninitialized storage
NULL if the request cannot be satisfied
Nothing
Both a &amp; b are true
47. calloc() returns a storage that is initialized to.
Zero
Null
Nothing
One
48. In function free(p), p is a:
int
Pointer returned by malloc()
Pointer returned by calloc()
Both b &amp; c
49. What is the output of this C code? void main() { char *p = calloc(100, 1); p = "welcome"; printf("%s ", p); }
Segmentation fault
garbage
Error
welcome
50. Memory allocation using malloc() is done in?
Static area
Stack area
Heap area
Both b &amp; c
51. Why do we write (int *) before malloc? int *ip = (int *)malloc(sizeof(int));
It is for the syntax correctness
It is for the type-casting
It is to inform malloc function about the data-type expected
None of the mentioned
52. Which one is used during memory deallocation in C?
remove(p);
delete(p);
free(p);
terminate(p);
53. Which of the following will return a result most quickly for searching a given key?
Unsorted Array
Sorted Array
Sorted linked list
Binary Search Tree
54. On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to?
NULL
Other dynamically allocated memory
The same deallocated memory location
It points back to location it was initialized with
55. calloc initialises memory with all bits set to zero.
True
False
Depends on the compiler
Depends on the standard
56. C99 standard guarantees uniqueness of ____ characters for internal names.
31
63
12
14
57. . C99 standard guarantess uniqueness of _____ characters for external names.
31
6
12
14
58. Which of the following is not a valid variable name declaration?
int __a3;
int __3a;
int __A3;
None of the mentioned
59. Variable names beginning with underscore is not encouraged. Why?
It is not standardized
To avoid conflicts since assemblers and loaders use such names
To avoid conflicts since library routines use such names
To avoid conflicts with environment variables of an operating system
60. All keywords in C are in?
Lower Case letters
Upper Case letters
Camel Case letters
None
61. Variable name resolving (number of significant characters for uniqueness of variable) depends on?
Compiler and linker implementations
Assemblers and loaders implementations
C Language
None
62. Which of the following is not a valid C variable name?
int number;
float rate;
int variable_count;
int $main;
63. Which of the following is true for variable names in C?
They can contain alphanumeric characters as well as special characters
It is not an error to declare a variable to be one of the keywords(like goto, static)
Variable names cannot start with a digit.
Variable can be of any length.
64. Which is valid C expression?
int my_num = 100,000;
int my_num = 100000;
int my num = 1000;
int $my_num = 10000;
65. What is the output of this C code? int main() { printf("Hello World! %d ", x); return 0; }
Hello World! x;
Hello World! followed by a junk value
Compile time error
Hello World!
66. What is the output of this C code? int main() { int y = 10000; int y = 34; printf("Hello World! %d ", y); return 0;
Compile time error
Hello World!
True
None of the mentioned
67. What will happen if the below program is executed? int main() { int main = 3; printf("%d", main); return 0; }
It will cause a compile-time error
It will cause a run-time error
It will run without any error and prints 3
It will experience infinite looping
68. What is the problem in following variable declaration? float 3Bedroom-Hall-Kitchen?;
The variable name begins with an integer
The special character &#039;-&#039;
The special character &#039;?&#039;
All of the mentioned
69. Which of the following cannot be a variable name in C?
Volatile
True
friend
export
70. Which of the following cannot be a variable name in C?
Volatile
True
friend
export
Submit