C MCQs (31-60)
31. Which of the following C functions is used to copy one string to another?
a) strcpy()
b) strcat()
c) strcpy_s()
d) copy_string()
Answer: a) strcpy()
32. Which of the following statements about pointers in C is FALSE?
a) A pointer holds the address of a variable.
b) Pointers can only point to variables of a single data type.
c) A pointer can store the address of a function.
d) A pointer can store any data type value.
Answer: d) A pointer can store any data type value.
33. What is the result of the following expression in C?
5 + 2 * 3 - 4 / 2
a) 10
b) 9
c) 8
d) 7
Answer: b) 9
34. Which of the following is the correct syntax to declare a function pointer in C?
a) int (ptr)();
b) int ptr();
c) ptr int();
d) ptr *int();
Answer: a) int (*ptr)();
35. In C, what is the difference between ==
and =
?
a) ==
is used for assignment, and =
is used for comparison.
b) ==
is used for comparison, and =
is used for assignment.
c) There is no difference.
d) ==
is used in conditional statements, and =
is used for logical operations.
Answer: b) ==
is used for comparison, and =
is used for assignment.
36. Which of the following is NOT a valid loop in C?
a) for
b) while
c) repeat
d) do-while
Answer: c) repeat
37. What will be the output of the following C program?
#include <stdio.h>
int main() {
int x = 10;
if (x == 10) {
printf("Hello");
} else {
printf("World");
}
return 0;
}
a) World
b) Hello
c) Error
d) Nothing
Answer: b) Hello
38. Which of the following is the correct syntax for a for
loop in C?
a) for (i = 0; i < 5; i++)
b) for i = 0; i < 5; i++
c) for (i = 0, i < 5, i++)
d) for i = 0, i < 5, i++
Answer: a) for (i = 0; i < 5; i++)
39. What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++ + ++x);
return 0;
}
a) 11
b) 10
c) 9
d) 12
Answer: a) 11
40. Which of the following is used to declare a variable that cannot be modified in C?
a) static
b) const
c) final
d) volatile
Answer: b) const
41. Which of the following functions can be used to allocate memory dynamically in C?
a) malloc()
b) calloc()
c) realloc()
d) All of the above
Answer: d) All of the above
42. What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 10;
int *ptr = &a;
printf("%d", *ptr);
return 0;
}
a) 10
b) Address of a
c) *ptr
d) Error
Answer: a) 10
43. In C, what is the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++ + x++);
return 0;
}
a) 11
b) 12
c) 10
d) Undefined
Answer: a) 11
44. In C, which of the following statements is true regarding the break
statement?
a) It terminates the loop and continues execution after the loop.
b) It terminates the program.
c) It exits from the function.
d) It continues the next iteration of the loop.
Answer: a) It terminates the loop and continues execution after the loop.
45. What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 4, b = 3;
printf("%d", a > b ? a : b);
return 0;
}
a) 4
b) 3
c) 7
d) Error
Answer: a) 4
46. Which of the following is used to define a constant value in C?
a) const
b) constant
c) static
d) #define
Answer: d) #define
47. What is the output of the following C code?
#include <stdio.h>
int main() {
char str[] = "Hello, World!";
printf("%s", str);
return 0;
}
a) Hello, World!
b) H e l l o , W o r l d !
c) Address of the string
d) Error
Answer: a) Hello, World!
48. Which of the following is the correct syntax to declare an array of 10 integers in C?
a) int arr[10];
b) int[10] arr;
c) arr[10] int;
d) array int arr[10];
Answer: a) int arr[10];
49. Which of the following statements is used to stop a loop in C?
a) stop
b) end
c) break
d) quit
Answer: c) break
50. Which of the following is NOT a valid function declaration in C?
a) int func();
b) func int();
c) void func();
d) int func(int a);
Answer: b) func int();
51. What will be the output of the following C code?
#include <stdio.h>
int main() {
int a = 10, b = 5;
printf("%d", a * b);
return 0;
}
a) 15
b) 50
c) 5
d) 10
Answer: b) 50
52. In C, which of the following is the correct way to define a pointer to a function?
a) int (*func_ptr)();
b) int *func_ptr();
c) func_ptr int();
d) func_ptr *int();
Answer: a) int (*func_ptr)();
53. What is the output of the following C code?
#include <stdio.h>
int main() {
int a = 10, b = 20;
printf("%d", a > b ? a : b);
return 0;
}
a) 20
b) 10
c) Error
d) 30
Answer: a) 20
54. Which of the following functions is used to compare two strings in C?
a) compare()
b) strcmp()
c) strcomp()
d) strcmp_s()
Answer: b) strcmp()
55. What is the size of a double
data type in C?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes
Answer: c) 8 bytes
56. Which of the following is the correct syntax to read a string in C?
a) scanf(“%d”, &str);
b) scanf(“%s”, str);
c) read(str);
d) get(str);
Answer: b) scanf(“%s”, str);
57. In C, what is the output of the following code?
#include <stdio.h>
int main() {
int i = 0;
for(i = 0; i < 5; i++) {
if(i == 2)
continue;
printf("%d ", i);
}
return 0;
}
a) 0 1 2 3 4
b) 0 1 3 4
c) 1 2 3 4
d) 0 2 4
Answer: b) 0 1 3 4
58. Which of the following functions is used to concatenate two strings in C?
a) concat()
b) strcat()
c) strconcat()
d) append()
Answer: b) strcat()
59. In C, which of the following statements is true about arrays?
a) The size of an array can be changed after it is defined.
b) Arrays in C always start at index 1.
c) The size of an array must be known at compile time.
d) Arrays can only store integers.
Answer: c) The size of an array must be known at compile time.
60. What is the default value of a variable declared as static
in C?
a) 0
b) Undefined
c) NULL
d) Random
Answer: a) 0