-
What is the output of the following code snippet?
int i = 5; printf("%d\n", ++i); a) 5 b) 6 c) Undefined behavior d) Compiler error
Answer: b) 6
-
Which symbol is used for a single-line comment in C?
a) //
b) /* */
c) #
d) <!-- -->Answer: a) //
-
What is the output of the following code snippet?
int a = 5, b = 10; printf("%d\n", a > b ? a : b);
a) 5
b) 10
c) Error
d) UndefinedAnswer: b) 10
-
In C, what is the function used to read a character from the standard input?
a) read()
b) getchar()
c) scanf()
d) gets()Answer: b) getchar()
-
What will be the output of the following code?
#include <stdio.h> int main() { int i = 0; while (i < 5) { printf("%d ", i++); } return 0; }
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3
d) Infinite loopAnswer: a) 0 1 2 3 4
-
Which of the following is NOT a valid data type in C?
a) double
b) char*
c) float
d) stringAnswer: d) string
-
What does the
scanf()
function return?a) The value entered by the user
b) The number of characters read
c) The number of format specifiers successfully matched and assigned
d) A pointer to the input bufferAnswer: c) The number of format specifiers successfully matched and assigned
-
Which operator is used to access the value stored at a particular address in C?
a) &
b) *
c) ->
d) ::Answer: b) * (asterisk)
-
In C, which of the following is NOT a valid way to initialize an array?
a) int arr[] = {1, 2, 3};
b) int arr[3] = {1, 2};
c) int arr[3]; arr = {1, 2, 3};
d) int arr[3]; arr[0] = 1; arr[1] = 2; arr[2] = 3;Answer: c) int arr[3]; arr = {1, 2, 3};
-
What will be the output of the following code?
#include <stdio.h> int main() { int arr[] = {1, 2, 3, 4, 5}; printf("%d\n", *arr + 2); return 0; }
a) 1
b) 3
c) 2
d) Compiler errorAnswer: b) 3
Comments