-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5; int y = 10; int z = (x > y) ? x : y; printf("%d\n", z); return 0; }
a) 5
b) 10
c) 15
d) Compiler errorAnswer: b) 10
-
Which keyword is used to terminate the execution of a function in C?
a) stop
b) end
c) return
d) terminateAnswer: c) return
-
What is the output of the following code snippet?
int x = 5, y = 10; printf("%d\n", x++); printf("%d\n", ++y);
a) 5, 11
b) 6, 11
c) 6, 10
d) 5, 10Answer: d) 5, 10
-
Which function is used to concatenate two strings in C?
a) strcat()
b) concat()
c) append()
d) join()Answer: a) strcat()
-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int i; for (i = 0; i < 5; i++) { if (i == 3) break; printf("%d ", i); } return 0; }
a) 0 1 2
b) 0 1 2 3
c) 0 1 2 3 4
d) Compiler errorAnswer: a) 0 1 2
-
Which escape sequence is used to print a newline character in C?
a) \n
b) \r
c) \t
d) \bAnswer: a) \n
-
What does the
calloc()
function do in C?a) Allocates memory on the stack
b) Allocates memory on the heap
c) Frees memory
d) Resizes memoryAnswer: b) Allocates memory on the heap
-
Which operator is used to find the remainder of division in C?
a) %
b) /
c) *
d) &Answer: a) %
-
What is the output of the following code snippet?
#include <stdio.h> int main() { int i; for (i = 0; i < 5; i++) { if (i == 3) continue; printf("%d ", i); } return 0; }
a) 0 1 2
b) 0 1 2 3
c) 0 1 2 4
d) Compiler errorAnswer: c) 0 1 2 4
-
Which function is used to dynamically deallocate memory in C?
a) free()
b) dealloc()
c) delete()
d) release()Answer: a) free()
Comments