-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int x = 0; while (x < 5) { printf("%d ", x++); } 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
-
In C, which function is used to read a line from a file?
a) fgets()
b) gets()
c) scanf()
d) read()Answer: a) fgets()
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 10; printf("%f\n", (float)x); return 0; }
a) 10.000000
b) 10
c) Compiler error
d) Undefined behaviorAnswer: a) 10.000000
-
Which of the following functions is used to find the square root of a number in C?
a) sqrt()
b) pow()
c) sqr()
d) root()Answer: a) sqrt()
-
What will be the output of the following code?
#include <stdio.h> int main() { char str[] = "Hello"; printf("%s\n", str + 2); return 0; }
a) Hello
b) lo
c) ello
d) Compiler errorAnswer: b) lo
-
Which operator is used to access the member of a structure in C?
a) . (dot)
b) -> (arrow)
c) : (colon)
d) :: (double colon)Answer: a) . (dot)
-
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 > x) ? y : (x = y)); return 0; }
a) 5
b) 10
c) 15
d) Compiler errorAnswer: b) 10
-
Which of the following is NOT a valid way to declare a structure variable in C?
a) struct { int x; } s;
b) struct s { int x; };
c) struct s { int x; } s;
d) struct s { int x; } s = {5};Answer: a) struct { int x; } s;
-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int i = 0; while (++i < 5) { printf("%d ", i++); } printf("%d\n", i); return 0; }
a) 1 3 5
b) 1 2 3 4
c) 2 4 6
d) 1 2 3Answer: b) 1 2 3 4
-
Which function is used to convert a floating-point number to a string in C?
a) atof()
b) ftoa()
c) dtoa()
d) float_to_string()Answer: c) dtoa()
Comments