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.122Easy
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.123Medium
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.124Medium
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.125Medium
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).
Advertisement
Q.126Medium
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.127Medium
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.128Medium
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.129Hard
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.
Q.130Hard
Consider: int *ptr = NULL; *ptr = 5; What will happen?
Answer: B
Attempting to dereference a NULL pointer causes undefined behavior, typically resulting in a segmentation fault (runtime error). A NULL pointer doesn't point to valid memory.
Q.131Easy
Which of the following is a correct way to declare a pointer to an integer in C?
Answer: B
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates it is a pointer variable.
Q.132Easy
What is the output of the following code: printf("%d", sizeof(int));
Answer: C
sizeof(int) returns the size of integer in bytes as an integer value. On most modern systems, this is 4 bytes, and printf with %d will print this numeric value.
Q.133Easy
Which of the following correctly initializes a 2D array in C?
Answer: C
Both syntaxes are valid in C. Option A explicitly specifies both dimensions, while Option B lets the compiler calculate the first dimension based on initialization.
Q.134Medium
What will be the output of: char ch = 'A'; printf("%d", ch);
Answer: B
When a character is printed using %d format specifier, its ASCII value is printed. The ASCII value of 'A' is 65.
Q.135Easy
Which of the following is NOT a valid identifier in C?
Answer: B
In C, an identifier cannot start with a digit. It must start with a letter (a-z, A-Z) or underscore (_). Option B violates this rule by starting with a digit.
Q.136Medium
What is the output of: int x = 5; int y = ++x + x++; printf("%d %d", x, y);
Answer: A
Step 1: x=5. Step 2: ++x makes x=6 (pre-increment, used immediately). Step 3: y = 6 + x++ = 6 + 6 = 12. Step 4: x++ increments x to 7 after use. Final: x=7, y=12.
Q.137Easy
In C, what is the difference between single quotes and double quotes?
Answer: B
In C, single quotes (') are used for single character constants (char type), while double quotes (") are used for string literals (array of characters ending with null terminator).
Q.138Medium
What is the output of: int a = 10, b = 20; a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d", a, b);
Answer: B
This is XOR swap algorithm. Step 1: a = 10^20. Step 2: b = (10^20)^20 = 10. Step 3: a = (10^20)^10 = 20. Result: a=20, b=10 (values are swapped).
Q.139Medium
In C, which function is used to read a string from input with space handling?
Answer: B
fgets() is the safe way to read strings including spaces. scanf("%s") stops at whitespace, gets() is deprecated and unsafe due to buffer overflow risks.
Q.140Medium
What is the purpose of the 'static' keyword when used with a variable inside a function?
Answer: B
A static variable inside a function is initialized only once and retains its value between successive function calls. It has memory allocated in the data segment, not the stack.