What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
Answer: A
strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.
Q.102Medium
What will be the output of: int x = 5; printf("%d", x << 1);
Answer: B
The left shift operator (<<) shifts bits to the left by 1 position, which is equivalent to multiplying by 2. So 5 << 1 = 10.
Q.103Medium
Consider the code: int arr[10]; int *p = arr; What is p[5]?
Answer: B
p points to arr, so p[5] is equivalent to *(p+5) which gives the value at arr[5].
Q.104Medium
What is the purpose of the void pointer in C?
Answer: D
The void pointer is a generic pointer that can hold addresses of any data type. void is also used for functions returning nothing and parameters.
Q.105Easy
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
Answer: A
The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)
Advertisement
Q.106Medium
Which function is used to read a string from standard input?
Answer: D
All three functions can read strings, though gets() is deprecated due to security issues. fgets() is safer as it limits input size.
Q.107Medium
What is the output of: int arr[] = {1,2,3,4,5}; printf("%d", sizeof(arr)/sizeof(arr[0]));
Answer: A
sizeof(arr) gives total size of array. sizeof(arr[0]) gives size of one element. Dividing gives the number of elements: 420 = 5.
Q.108Easy
Which of the following correctly initializes a 2D array?
Answer: C
Both syntaxes are correct. C allows initializing 2D arrays with or without explicit braces for each row.
Q.109Easy
What will be the output of: printf("%d", 25);
Answer: B
Integer division truncates the decimal part. 25 = 2 (not 2.5) because both operands are integers.
Q.110Easy
What does the getchar() function do?
Answer: A
getchar() reads a single character from standard input (stdin) and returns its ASCII value.
Q.111Easy
What will be the output of: int a = 5, b = 5; if(a == b) printf("Equal"); else printf("Not Equal");
Answer: A
The == operator compares values. Since a and b both have value 5, the condition is true and "Equal" is printed.
Q.112Medium
What will be the output of: char c = 'A'; printf("%d", c);
Answer: A
The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.
Q.113Easy
Which header file is essential for using the printf() function in C?
Answer: B
The stdio.h header file contains declarations for standard input/output functions like printf(). Option A is C++, Option C is C++, and Option D is for memory allocation functions.
Q.114Medium
What is the output of: int arr[5]; printf("%d", sizeof(arr));
Answer: C
sizeof(arr) returns the total size of the array in bytes. An array of 5 integers, where each int is 4 bytes, equals 5 × 4 = 20 bytes.
Q.115Medium
Which function is used to allocate memory dynamically at runtime?
Answer: B
malloc() is the standard C library function for dynamic memory allocation. It returns a void pointer to the allocated memory block, which can be cast to the required data type.
Q.116Medium
What is the purpose of the break statement in a switch case?
Answer: B
The break statement terminates the current loop or switch block and transfers control to the statement following the loop or switch. Without it, execution continues to the next case (fall-through).
Q.117Medium
What will be the output of: int x = 5, y = 10; if (x < y) printf("yes"); else printf("no");
Answer: A
The condition x < y evaluates to true (5 < 10), so the if block executes, printing 'yes'. The else block is skipped.
Q.118Medium
Which of the following is NOT a valid way to pass arguments to a function in C?
Answer: B
C supports pass by value and pass by pointer/address. 'Pass by reference' as a concept exists in C++, not in C. In C, to achieve reference-like behavior, we use pointers.
Q.119Medium
What will be the result of: int a = 10, b = 3; int c = a % b; printf("%d", c);
Answer: B
The modulus operator % returns the remainder of division. 10 % 3 = 1 (since 10 = 3 × 3 + 1). Therefore, c = 1 and the output is 1.
Q.120Hard
What happens if you declare a variable but don't initialize it in C?
Answer: B
Uninitialized local variables contain garbage values (unpredictable values from previous memory contents). Global and static variables are automatically initialized to 0, but local variables are not.