C Multiple Choice Questions
C Multiple Choice Questions
C Multiple Choice Questions
1. Which among the following is never possible in C when members are different in a structure and union?
//Let P be a structure
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is less than sizeof(Q)
c. sizeof(P) is equal to sizeof(Q)
d. None of the mentioned
Answer:d
2. Which among the following is never possible in C when members in a structure are same as that in a
union?
//Let P be a structure
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is equal to sizeof(Q)
c. sizeof(P) is less than to sizeof(Q)
d. None of the mentioned
Answer:c
3. What will be the size of the following structure?
1. #include <stdio.h>
2. struct temp
3. {
4. int a[10];
5. char p;
6. };
a. 5 b. 11 c. 41 d. 44
Answer:d
4. Comment on the output of following C program?
1. #include <stdio.h>
2. main()
3. {
4. int a = 1;
5. printf("size of a is %d, ", sizeof(++a));
6. printf("value of a is %d", a);
7. };
a. size of a is 4, value of a is 1
b. size of a is 4, value of a is 2
c. size of a is 2, value of a is 2
d. size of a is 2, value of a is 2
Answer:a
5. Which among the following is right?
a. sizeof(struct stemp*) > sizeof(union utemp*) > sizeof(char *)
b. sizeof(struct stemp*) < sizeof(union utemp*) < sizeof(char *)
c. sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)
d. The order Depends on the compiler
Answer:c
6. Comment on the following C code?
1. #include <stdio.h>
2. printf("%d", sizeof(strlen("HELLOWORLD")));
a. Output, 4
b. Output, 10
c. Output, 16
d. Error, sizeof cannot evaluate size of a function.
Answer:a
7. Which of the following cannot be used inside sizeof?
a. pointers
b. functions
c. macro definition
d. None of the mentioned
Answer:d
8. Comment on the following C code?
1. #include <stdio.h>
2. (sizeof double = 8, float = 4, void = 1)
3. #define PI 3.14
4. int main()
5. {
6. printf("%d", sizeof(PI));
7. }
a. Output is 8
b. Output is 4
c. Output is 1
d. Error, we can’t use sizeof on macro-definitions
Answer:a
56. Which of the following mathematical function requires 2 parameter for successful function call?
a) fmod();
b) div();
c) atan2();
d) All of the mentioned.
Answer:d
57. Which mathematical function among the following does NOT require int parameters?
a) div(x, y);
b) srand(x);
c) sqrt(x);
d) All of the mentioned.
Answer:c
58. sin(x) returns
a) sine of x where x is in radians
b) sine of x where x is in degree
c) cosine of x where x is in radians
d) cosine of x where x is in degree
Answer:a
59. cos(x) returns
a) sine of x where x is in radians
b) sine of x where x is in degree
c) cosine of x where x is in radians
d) cosine of x where x is in degree
Answer:c
60. What is the output of this C code?
1. #include <stdio.h>
2. #include <math.h>
3. void main()
4. {
5. int k = pow(2, 3);
6. printf("%d\n", k);
7. }
a) 9
b) 8
c) -1
d) 6
Answer:b
61. What is the output of this C code?
1. #include <stdio.h>
2. #include <math.h>
3. void main()
4. {
5. int k = fabs(-87);
6. printf("%d\n", k);
7. }
a) -87
b) 87
c) 78
d) error
Answer:b
62. What is the output of this C code?
1. #include <stdio.h>
2. #include <math.h>
3. void main()
4. {
5. int k = sqrt(-4);
6. printf("%d\n", k);
7. }
a) -2
b) 2
c) Compile time error
d) NaN
Answer:d
63. Which among the following mathematical function do not have a “double” return-type?
a) srand(x);
b) ceil(x);
c) floor(x);
d) Both (b) and (c);
Answer:a
72. Which of the following will return a result most quickly for searching a given key?
a) Unsorted Array
b) Sorted Array
c) Sorted linked list
d) Binary Search Tree
Answer:d
73. On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to.
a) NULL
b) Other dynamically allocated memory
c) The same deallocated memory location
d) It points back to location it was initialized with
Answer:c
74. For the following program, Which of the following should be used for freeing the memory allocated?
1. #include <stdio.h>
2. struct p
3. {
4. struct p *next;
5. int x;
6. };
7. int main()
8. {
9. struct p *p1 = (struct p*)malloc(sizeof(struct p));
10. p1->x = 1;
11. p1->next = (struct p*)malloc(sizeof(struct p));
12. return 0;
13. }
a) free(p1);
free(p1->next)
b) free(p1->next);
free(p1);
c) free(p1);
d) All of the mentioned
Answer:b
75. What is the output of this C code?
1. #include <stdio.h>
2. struct p
3. {
4. struct p *next;
5. int x;
6. };
7. int main()
8. {
9. struct p *p1 = calloc(1, sizeof(struct p));
10. p1->x = 1;
11. p1->next = calloc(1, sizeof(struct p));
12. printf("%d\n", p1->next->x);
13. return 0;
14. }
a) Compile time error
b) 1
c) Somegarbage value
d) 0
Answer:d
76. What is the output of this C code?
1. #include <stdio.h>
2. struct p
3. {
4. struct p *next;
5. int x;
6. };
7. int main()
8. {
9. struct p* p1 = malloc(sizeof(struct p));
10. p1->x = 1;
11. p1->next = malloc(sizeof(struct p));
12. printf("%d\n", p1->next->x);
13. return 0;
14. }
a) Compile time error
b) 1
c) Somegarbage value
d) 0
Answer:c
77. calloc initialises memory with all bits set to zero.
a) true
b) false
c) Depends on the compiler
d) Depends on the standard
Answer:a
78. realloc(ptr, size), where size is zero means
a) Allocate a memory location with zero length
b) Free the memory pointed to by ptr
c) Undefined behaviour
d) Doesn’t do any reallocation of ptr i.e. no operation
Answer:b