1. What is the size of the int data type in C (On a 32-bit system)?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) It depends on the compiler
Answer: B) 4 bytes
2. Which of the following is a correct format specifier for printing float value??
A) %d
B) %c
C) %f
D) %lf
Answer: C) %f
3. Which of the following operators is used to dereference a pointer?
A) &
B) *
C) ->
D).
Answer: B) *
4. So this produces the above output.
int x = 5;
printf(“%d”, x++);
A) 4
B) 5
C) 6
D) Compilation error
Answer: B) 5
5. Which of the following is not a valid C variable name?
A) my_var
B) _var
C) 2ndVar
D) Var2
Answer: C) 2ndVar
6. The type returned by functions in C, if no value is specified explicitly
A) void
B) int
C) float
D) char
Answer: B) int
7. Output:
int a = 10;
int b = 20;
int c = a > b ? a : b;
printf(“%d”, c);
A) 10
B) 20
C) 0
D) Compilation error
Answer: B) 20
Functions and control flows, Loops
8. Output of the code
void func() {
static int x = 0;
printf(“%d “, ++x);
}
int main() {
func();
func();
return 0;
}
A) 1 1
B) 1 2
C) 2 3
D) Compilation error
Answer: B) 1 2
9. Even more Control structures in C MCQs
A) continue
B) break
C) exit()
D) return
Answer: B) break
10. Which of the following loops does it execute for?
int i;
for (i = 0; i < 10; i++);
A) 9
B) 10
C) Infinite loop
D) 11
Answer: B) 10
11. C functions to compare two strings___________________________________________________________________________
A) strcmp()
B) strlen()
C) strcpy()
D) strcat()
Answer: A) strcmp()
12. How does this code change? 2. Q: What will the following code output?
int i = 0;
while (i++ < 5) {
printf(“%d “, i);
}
A) 0 1 2 3 4
B) 1 2 3 4 5
C) 1 2 3 4
D) Infinite loop
Answer: B) 1 2 3 4 5
13. What Keyword should be used for c to keep a function or variable constant?
A) static
B) const
C) volatile
D) extern
Answer: B) const
Pointer and Memory Management
14. How should I declare a pointer to an integer?
A) int *ptr;
B) int &ptr;
C) ptr int*;
D) *int ptr;
Answer: A) int *ptr;
15. How Would That Look in Code?
int arr[5] = {1, 2, 3, 4, 5};
printf(“%d”, *(arr + 2));
A) 1
B) 2
C) 3
D) Compilation error
Answer: C) 3
16. What will that code return?
int x = 10;
int *p = &x;
printf(“%d”, *p);
A) Memory address of x
B) 10
C) 0
D) Compilation error
Answer: B) 10
17. ______________use for Dynamic memory in c?
A) malloc()
B) free()
C) new()
D) delete()
Answer: A) malloc()
18. Noopes, so how to do it in C?
A) release()
B) free()
C) delete()
D) remove()
Answer: B) free()
19. The output of the code is —
int x = 5;
int *p = &x;
*p = 10;
printf(“%d”, x);
A) 5
B) 10
C) 0
D) Compilation error
Answer: B) 10
20. The result of the following code is?
int x = 5, y = 10;
int *p = &x, *q = &y;
p = q;
printf(“%d”, *p);
A) 5
B) 10
C) 0
D) Compilation error
Answer: B) 10
21. Which of the following is the correct way to declare an array in C?
A) int arr[5] = {1, 2, 3,4,5};
B) int arr() = {1, 2, 3, 4,5 };
C) arr[5] int ={1,2,3,,4,5};
D) int[ ] arr = {1, 2,3,4,5};
Answer: A) int arr[5] = {1, 2, 3,4,5};
22. What is the output of this code next?
char str[] = “Hello”;
printf(“%c”, str[1]);
A) H
B) e
C) l
D) o
Answer: B) e
23. Which is true about Recursion in C?
A) We cannot write a recursive function in CsetOnClickListener →
B) StackOverflow may happen if Recursion
C) Slower than iteration
D) The recursive function takes an array
Answer: B) StackOverflow may happen if Recursion
24. What the output from a recursive function appears to be.getenv Digital(outputs -> Recursion)
Output:
int fact(int n) {
if (n == 0) return 1;
else return n * fact(n – 1);
}
printf(“%d”, fact(4));
A) 4
B) 16
C) 24
D) 120
Answer: C) 24
25. Which of the following C functions copies string from one location to another?
A) strcpy()
B) strcat()
C) strcmp()
D) strstr()
Answer: A) strcpy()
26. What is going to be the output after this operation?
int x = 5; // Binary: 0101
int y = x << 1;
printf(“%d”, y);
A) 2
B) 5
C) 10
D) 20
Answer: C) 10
27. Output:torch.tensor([ 1, -3])
int a = 5, b = 3;
int result = a & b;
printf(“%d”, result);
A) 1
B) 2
C) 3
D) 0
Answer: A) 1
28. Which of the function we are using to read a file in C A. sweaty () B. jspb() c fgetID, D scan (.,.), E. SGETS 11
A) write()
B) fscanf()
C) open()
D) read()
Answer: D) read()
29. Solution: Open the file in write mode that already exists ( erases old files )
A) “r”
B) “w+”
C) “a+”
D) “r+”
Answer: B) “w+”
30. File handling in C! Which of the following is true about reading and writing files?
A) fexit()
B) fend()
C) fclose()
D) exit()
Answer: C) fclose ()