C Programming Coding Questions And Answers PDF
1. What is the output of the expression sizeof(int)
in C?
a) 4 bytes
b) 8 bytes
c) Compiler dependent
d) 2 bytes
2. Which of the following is a valid C variable name?
a) 3variable
b) variable_3
c) variable-3
d) variable 3
3. What is the result of the expression 3 + 4 * 2
in C?
a) 14
b) 10
c) 11
d) 24
4. Which keyword is used to define a constant in C?
a) const
b) define
c) static
d) #define
5. How do you access the first element of an array named arr
in C?
a) arr[0]
b) arr[1]
c) arr[First]
d) arr[first]
6. Which header file is required to use the printf
function in C?
a) <stdio.h>
b) <stdlib.h>
c) <stdio.h>
d) <math.h>
7. What does the printf
function do in C?
a) Reads input from the user
b) Prints formatted output to the console
c) Performs mathematical calculations
d) Allocates memory for variables
8. Which operator accesses the value at a memory address in C?
a) * (asterisk)
b) & (ampersand)
c) -> (pointer arrow operator)
d):: (scope resolution operator)
9. What is the purpose of the break
statement in C?
a) To end the program
b) To terminate the current loop or switch statement
c) To skip the current iteration in a loop
d) To resume the next iteration of a loop
10. What does the %d
format specifier represents in the printf
function in C?
a) Double
b) Decimal
c) Character
d) Integer
11. Which keyword is used to define a structure in C?
a) class
b) struct
c) struct
d) typedef
12. What is the result of the expression sizeof(float)
in C?
a) 4 bytes
b) Compiler dependent
c) 8 bytes
d) 2 bytes
13. How do you access the last element of an array named arr
in C?
a) arr[end]
b) arr[length(arr)]
c) arr[length(arr) – 1]
d) arr[length – 1]
Elizabeth and Restoration Drama MCQ (Multiple Choice Questions)
14. Which operator is used for logical AND in C?
a) &
b) &&
c) &&
d) ||
15. What is the output of the following code?
int x = 5, y = 10; printf(“%d”, x++ + ++y);
a) 15
b) 16
c) 16
d) 17
16. What is the purpose of the continue
statement in C?
a) To end the loop
b) To exit the program
c) To skip the remaining code inside a loop and continue with the next iteration
d) To print the current value of the loop variable
17. Which of the following is not a valid data type in C?
a) int
b) char
c) float
d) string
18. What is the result of the expression 2 << 3
in C?
a) 6
b) 16
c) 5
d) 8
19. Which function reads a character from the standard input in C?
a) getc()
b) getchar()
c) gets()
d) read()
20. What is the purpose of the return
statement in C?
a) To exit the program
b) To print output to the console
c) To return a value from a function
d) To skip the remaining code inside a loop
21. What is the output of the following code snippet?
int i = 0; for (; i < 5;) printf(“%d “, ++i);
a) 1 2 3 4 5
b) 0 1 2 3 4
c) 1 2 3 4 5
d) 0 1 2 3 4 5
22. Which of the following is a valid comment in C?
a) ‘This is a comment’
b) // This is a comment
c) /* This is a comment */
d) # This is a comment
23. What is the output of the following code snippet?
int x = 10, y = 5; printf(“%d”, x / y);
a) 2.0
b) 2
c) 2.5
d) 5
24. What is the purpose of the goto
statement in C?
a) To skip the current iteration of a loop
b) To transfer control to a labeled statement
c) To exit the program
d) To print output to the console
25. What is the output of the following code snippet?
printf("%c", 65);
a) A
b) 65
c) 97
d) Error
Laplace Transform MCQ (Multiple Choice Questions)
26. Which function is used to compare two strings in C?
a) strcmp()
b) strncmp()
c) strcasecmp()
d) strcoll()
27. What is the result of the expression 10 % 3
in C?
a) 0.3333
b) 1
c) 1
d) 3
28. What is the output of the following code snippet?
int x = 10, y = 5; x *= y + 2; printf(“%d”, x);
a) 30
b) 60
c) 35
d) 50
29. Which of the following is not a valid arithmetic operator in C?
a) +
b) *
c) &
d) /
30. What is the output of the following code?
printf("%d", sizeof(float));
a) 4
b) Compiler dependent
c) 8
d) 2
31. What is the purpose of the sizeof
operator in C?
a) To calculate the size of a variable
b) To determine the size of a data type
c) To allocate memory dynamically
d) To concatenate strings
32. What is the output of the following code?
int x = 5, y = 5; printf(“%d”, x == y);
a) True
b) 1
c) False
d) 0
33. Which is not a valid relational operator in C?
a) ==
b) !=
c) <>
d) ><
34. What is the output of the following code?
int x = 5; printf("%d", x++);
a) 5
b) 5 followed by increment
c) 6
d) Compilation error
35. What is the result of the expression ++x + x++
if x = 5
in C?
a) 11
b) Compiler dependent
c) 10
d) 12
36. What is the purpose of the continue
statement in C?
a) To end the program
b) To skip the remaining code inside a loop and continue with the next iteration
c) To exit the loop
d) To restart the loop
37. What is the output of the following code?
int x = 10, y = 5; printf(“%d”, x– – –y);
a) 4
b) 5
c) 6
d) 7
38. What is the output of the following code?
int x = 10, y = 5; printf(“%d”, (x > 10) && (y < 10));
a) 1
b) 0
c) True
d) False
39. Which is not a valid logical operator in C?
a) &&
b) ||
c) ><
d) !
40. What is the purpose of the return
statement in C?
a) To exit the program
b) To print output to the console
c) To return a value from a function
d) To skip the remaining code inside a loop
41. What is the output of the following code?
int x = 10, y = 5; printf(“%d”, (x > 5) ? x : y);
a) 10
b) 5
c) 10
d) 5
42. What is the purpose of the sizeof
operator in C?
a) To calculate the size of a variable
b) To determine the size of a data type
c) To allocate memory dynamically
d) To concatenate strings
43. What is the output of the following code?
int x = 10, y = 5; x += y + 2; printf(“%d”, x);
a) 10
b) 17
c) 7
d) 15
44. What is the purpose of the goto
statement in C?
a) To terminate the current loop or switch statement
b) To transfer control to a labeled statement
c) To print output to the console
d) To skip the remaining code inside a loop
45. What is the output of the following code?
int x = 5, y = 10; printf(“%d”, x / y);
a) 0.5
b) 0
c) 0.0
d) 0.5
46. Which function reads a string from the standard input in C?
a) gets()
b) fgets()
c) scanf()
d) read()
47. What is the output of the following C code?
int x = 5; printf(“%c”, x);
a) 5
b) ASCII character corresponding to 5
c) Error
d) 53
48. Which of the following is not a valid string manipulation function in C?
a) strcpy()
b) strcat()
c) strlen()
d) strrev()
49. What is the output of the following code?
int x = 10; printf(“%d”, sizeof(x));
a) 1
b) 2
c) Compiler dependent
d) 4
50. What is the purpose of the #include
directive in C?
a) To define a macro
b) To declare a function
c) To include a header file
d) To include standard input/output functions
51. What will be the output of the following C code?
- #include <stdio.h>
- void main()
- {
- int x = 5;
- if (x < 1)
- printf(“hello”);
- if (x == 5)
- printf(“hi”);
- else
- printf(“no”);
- }
a) hi
b) hello
c) no
d) error