-
What is the output of the following code?
#include <stdio.h> int main() { int arr[] = {1, 2, 3, 4, 5}; int *ptr = arr; printf("%d\n", *(ptr + 2)); return 0; }
a) 1
b) 2
c) 3
d) 4Answer: c) 3
-
Which function is used to find the largest integer not greater than x in C?
a) ceil()
b) floor()
c) round()
d) trunc()Answer: b) floor()
-
What will be 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); printf("%d\n", y); return 0; }
a) 5, 6, 10
b) 5, 6, 11
c) 5, 5, 10
d) 5, 5, 11Answer: a) 5, 6, 10
-
Which of the following is used to access the last element of an array in C?
a) arr[length - 1]
b) arr[length]
c) arr[length + 1]
d) arr[-1]Answer: a) arr[length - 1]
-
What will be the output of the following code?
#include <stdio.h> int main() { char str[] = "Hello"; printf("%c\n", str[5]); return 0; }
a) H
b) e
c) l
d) \0Answer: d) \0
-
Which of the following is the correct syntax for declaring a structure in C?
a) struct { int x; };
b) structure { int x; };
c) struct x { int x; };
d) struct { int x; } x;Answer: c) struct x { int x; };
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5, y = 10; if (x > y) printf("x is greater than y\n"); else if (x < y) printf("x is less than y\n"); else printf("x is equal to y\n"); return 0; }
a) x is greater than y
b) x is less than y
c) x is equal to y
d) No outputAnswer: b) x is less than y
-
Which function is used to convert a string to an integer in C?
a) atoi()
b) itoa()
c) atoi()
d) strtoi()Answer: a) atoi()
-
What does the
strchr()
function in C do?a) Finds the first occurrence of a character in a string
b) Compares two strings
c) Copies one string to another
d) Concatenates two stringsAnswer: a) Finds the first occurrence of a character in a string
-
What is the output of the following code?
#include <stdio.h> int main() { int x = 5; printf("%d\n", x << 2); return 0; }
a) 5
b) 10
c) 20
d) 40Answer: c) 20
Comments