-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int i = 0; for (; i < 5; i++) { printf("%d ", i++); } printf("%d\n", i); return 0; }
a) 0 2 4 6
b) 1 3 5
c) 0 1 2 3 4
d) 1 2 3 4 5Answer: c) 0 1 2 3 4
-
In C, which of the following functions is used to close a file?
a) close()
b) fclose()
c) endfile()
d) fileclose()Answer: b) fclose()
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5, y = 10; printf("%d\n", (x > y) ? (x++) : (y--)); printf("%d %d\n", x, y); return 0; }
a) 5, 5, 9
b) 5, 10, 9
c) 10, 5, 9
d) 10, 10, 9Answer: b) 5, 10, 9
-
Which of the following functions is used to read a single character from the standard input in C?
a) getchar()
b) gets()
c) scanf()
d) read()Answer: a) getchar()
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5; printf("%lf\n", (double)x); return 0; }
a) 5.000000
b) 5
c) Compiler error
d) Undefined behaviorAnswer: a) 5.000000
-
In C, which of the following operators is used to access the address of a variable?
a) &
b) *
c) ->
d) .Answer: a) &
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5, y = 10; printf("%d\n", (x > y) ? (x--) : (y++)); printf("%d %d\n", x, y); return 0; }
a) 5, 6, 11
b) 5, 10, 11
c) 10, 4, 11
d) 10, 11, 11Answer: b) 5, 10, 11
-
What does the
fgets()
function in C do?a) Reads a line from a file
b) Reads a character from a file
c) Reads a line from the console
d) Reads a character from the consoleAnswer: a) Reads a line from a file
-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int x = 5; while (x) { printf("%d ", x--); } printf("%d\n", x); return 0; }
a) 5 4 3 2 1 0
b) 5 4 3 2 1
c) 4 3 2 1 0
d) 4 3 2 1Answer: a) 5 4 3 2 1 0
-
In C, which function is used to convert a string to a floating-point number?
a) atof()
b) atoi()
c) strtod()
d) float_convert()
**Answer: a) atof()**
Comments