-
Which statement is used to dynamically allocate memory for an array in C?
a) new
b) malloc
c) allocate
d) array_allocAnswer: b) malloc
-
What will be the output of the following code?
#include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; int *ptr = arr; printf("%d\n", *++ptr); return 0; }
a) 1
b) 2
c) 3
d) Compiler errorAnswer: b) 2
-
In C, what does the
static
keyword mean when used with a global variable?a) The variable cannot be accessed from outside the file it is defined in
b) The variable is only accessible within the function it is defined in
c) The variable retains its value between function calls
d) The variable cannot be modified after initializationAnswer: c) The variable retains its value between function calls
-
What will be the output of the following code?
#include <stdio.h> int main() { int i = 0; do { printf("%d ", i); i++; } while (i < 5); return 0; }
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 1 2 3 4
d) Compiler errorAnswer: a) 0 1 2 3 4
-
What does the
strcat()
function in C do?a) Compares two strings
b) Copies one string to another
c) Concatenates two strings
d) Searches for a substring in a stringAnswer: c) Concatenates two strings
-
Which header file is required to use the
strlen()
function in C?a) <stdio.h>
b) <stdlib.h>
c) <string.h>
d) <ctype.h>Answer: c) <string.h>
-
What is the output of the following code snippet?
#include <stdio.h> int main() { int x = 5, y = 10; printf("%d\n", x > y ? x : y); return 0; }
a) 5
b) 10
c) 15
d) Compiler errorAnswer: b) 10
-
What does the
putc()
function do in C?a) Reads a character from a file
b) Writes a character to a file
c) Reads a character from the console
d) Writes a character to the consoleAnswer: b) Writes a character to a file
-
What will be the output of the following code?
#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
a) Hello, world!
b) Compiler error
c) Undefined behavior
d) No outputAnswer: a) Hello, world!
-
What is the output of the following code snippet?
#include <stdio.h> int main() { int x = 5, y = 10; printf("%d\n", (x < y) && (x++ < y)); printf("%d\n", x); return 0; }
a) 1, 6
b) 1, 5
c) 0, 6
d) 0, 5Answer: b) 1, 5
Comments