What is the output of the following C code?
int x = 5;
printf("%d", x++);
Answer: B
The post-increment operator (x++) returns the current value of x before incrementing. So printf prints 5, and then x becomes 6.
Q.2Easy
Which of the following is the correct syntax to declare a pointer in C?
Answer: A
In C, pointers are declared using the asterisk (*) symbol before the variable name. The syntax is 'datatype *pointer_name;'
Q.3Easy
What will be the size of the following array in bytes?
char arr[10];
Answer: A
Each char occupies 1 byte in memory. An array of 10 chars will occupy 10 × 1 = 10 bytes.
Q.4Easy
What is the purpose of the 'void' keyword in C?
Answer: C
void is used in two contexts: (1) as a function return type when a function doesn't return a value, and (2) to declare a generic pointer (void *) that can point to any data type.
Q.5Easy
What is the output of the following C code?
int a = 10, b = 20;
int c = (a > b) ? a : b;
printf("%d", c);
Answer: B
The ternary operator (condition ? true_value : false_value) evaluates the condition (a > b). Since 10 is not greater than 20, it returns b which is 20.
Advertisement
Q.6Easy
What does the strlen() function return?
Answer: B
strlen() returns the length of a string without counting the null terminator ('\0'). For example, strlen("hello") returns 5, not 6.
Q.7Easy
Which header file is required to use the printf() function in C?
Answer: B
The stdio.h header file contains declarations for standard input/output functions like printf() and scanf().
Q.8Easy
Which of the following is a valid variable name in C?
Answer: B
Variable names in C must start with a letter or underscore, not a digit. _variable is valid. '2var' starts with digit, 'var-name' contains hyphen (invalid), 'var name' contains space (invalid).
Q.9Easy
What is the return type of the strlen() function?
Answer: C
The strlen() function returns the length of a string as an int value, representing the number of characters.
Q.10Easy
Which operator has the highest precedence in C?
Answer: C
Parentheses () have the highest precedence among all operators in C. They are always evaluated first in any expression.
Q.11Easy
What is the size of an integer variable in most modern C compilers?
Answer: B
On most modern 32-bit and 64-bit systems, an int is typically 4 bytes (32 bits). However, the exact size can vary depending on the compiler and system architecture.
Q.12Easy
Which of the following is NOT a valid C data type?
Answer: B
C does not have a built-in boolean data type. The other options (float, double, char) are all valid primitive data types in C. Boolean functionality is typically implemented using int (0 for false, non-zero for true).
Q.13Easy
What is the purpose of the & operator in C?
Answer: C
The & operator has two uses in C: (1) When used before a variable, it returns the memory address of that variable (address-of operator), and (2) When used between two integers, it performs a bitwise AND operation.
Q.14Easy
Which keyword is used to create a constant variable in C?
Answer: C
The const keyword is used in C to declare a constant variable whose value cannot be modified after initialization. Variables declared as const are read-only.
Q.15Easy
What is the output of sizeof(char) in C?
Answer: B
By the C standard, sizeof(char) is always 1 byte. A char is the smallest addressable unit in C and is defined to be 1 byte.
Q.16Easy
How many times will the loop execute?
for(int i = 0; i < 5; i++)
Answer: B
The loop initializes i to 0 and continues while i < 5. Values of i: 0, 1, 2, 3, 4. After i becomes 5, the condition is false, so the loop executes 5 times.
Q.17Easy
What will be the value of x after: int x = 5; x += 3;
Answer: C
The += operator is a compound assignment operator. x += 3 is equivalent to x = x + 3. Therefore, 5 + 3 = 8.
Q.18Easy
What is the size of int data type in a 32-bit system?
Answer: B
In a 32-bit system, the int data type typically occupies 4 bytes (32 bits). This is the standard size for integer types on most 32-bit architectures.
Q.19Easy
Which header file is required to use the printf() function?
Answer: B
The stdio.h (Standard Input Output) header file contains declarations for printf(), scanf(), and other input/output functions. It is essential for console I/O operations.
Q.20Easy
In C, which operator has the highest precedence?
Answer: C
Parentheses have the highest precedence in C. Expressions within parentheses are evaluated first, followed by arithmetic operators, then logical operators, and finally assignment operators.