-
What will be the output of the following code snippet?
#include <stdio.h> int main() { int i = 0; for (; i < 5; ++i) { if (i == 2) break; printf("%d ", i); } printf("%d\n", i); return 0; }
a) 0 1 2
b) 0 1 3
c) 0 1 4
d) 0 2Answer: a) 0 1 2
-
In C, which escape sequence is used to represent a backslash character?
a) \b
b) \t
c) \n
d) \Answer: d) \
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 10; printf("%d\n", x++); printf("%d\n", x); return 0; }
a) 10, 11
b) 10, 10
c) 11, 11
d) 11, 10Answer: a) 10, 11
-
Which function is used to find the smallest integer not less than x in C?
a) ceil()
b) floor()
c) round()
d) trunc()Answer: a) ceil()
-
What does the
isalpha()
function in C do?a) Checks if a character is alphabetic
b) Checks if a character is a digit
c) Checks if a character is a whitespace character
d) Checks if a character is a punctuation characterAnswer: a) Checks if a character is alphabetic
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 10; printf("%d\n", x / 3); return 0; }
a) 3
b) 3.3333
c) 3.0
d) Compiler errorAnswer: a) 3
-
Which of the following is NOT a valid way to declare and initialize a string in C?
a) char str[] = "Hello";
b) char str[6] = "Hello";
c) char str[] = {'H', 'e', 'l', 'l', 'o', '\0'};
d) char str[5] = "Hello";Answer: d) char str[5] = "Hello";
-
What is the output of the following code?
#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 error
Answer: b) 10
-
What does the
strncpy()
function in C do?a) Copies one string to another
b) Compares two strings
c) Concatenates two strings
d) Copies a specified number of characters from one string to anotherAnswer: d) Copies a specified number of characters from one string to another
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 10; printf("%p\n", &x); return 0; }
a) Address of x
b) Value of x
c) Address of ptr
d) Compiler errorAnswer: a) Address of x
Comments