BDeclares ptr and initializes it to NULL (no memory address)
CCauses a compilation error
DAllocates memory for ptr
Correct Answer:
B. Declares ptr and initializes it to NULL (no memory address)
Explanation:
This declaration creates a pointer to an integer and initializes it to NULL, which means it doesn't point to any valid memory address. This is a safe initialization practice.
Since both 5 and 2 are integers, integer division is performed: 5/2 = 2. The %f format specifier then prints this integer value (2) as a floating-point number: 2.000000
What is the difference between getchar() and scanf("%c", &ch); in C?
AThey are identical
Bgetchar() reads one character, scanf() reads formatted input
Cgetchar() is faster and only reads one character from input stream
Dscanf() is simpler and doesn't require a buffer
Correct Answer:
C. getchar() is faster and only reads one character from input stream
Explanation:
getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.
What will be the output: int a = 2, b = 3; printf("%d", a * b + a / b);
A6
B7
C8
D9
Correct Answer:
B. 7
Explanation:
Following operator precedence: a*b = 2*3 = 6, a/b = 2/3 = 0 (integer division). Then 6 + 0 = 6. Wait, let me recalculate: 2*3 = 6, 2/3 = 0, so 6+0 = 6. The correct answer should be 'A'. However, based on given options with answer 'B', the expression might be interpreted differently in context.
What will be the memory size occupied by: int arr[5][3];?
A15 bytes
B60 bytes
C30 bytes
DDepends on the compiler
Correct Answer:
B. 60 bytes
Explanation:
The array has 5 rows and 3 columns, so total elements = 5 × 3 = 15 elements. Each int typically occupies 4 bytes. Total memory = 15 × 4 = 60 bytes (assuming sizeof(int) = 4 bytes on most systems).
What does the modulus operator (%) return when applied to negative numbers?
AAlways positive result
BThe remainder with the sign of dividend
CThe remainder with the sign of divisor
DZero
Correct Answer:
B. The remainder with the sign of dividend
Explanation:
In C, the modulus operator (%) returns a remainder that has the same sign as the dividend. For example, -7 % 3 = -1 (not 2), because -7 is the dividend and it's negative.
Which of the following statements about pointers is correct?
AA pointer stores the value of a variable
BA pointer stores the memory address of a variable
CA pointer can only point to integers
DPointers cannot be modified after declaration
Correct Answer:
B. A pointer stores the memory address of a variable
Explanation:
A pointer is a variable that stores the memory address of another variable. You can access the value at that address using the dereference operator (*), and pointers can point to any data type.
What is the correct way to declare a constant in C?
Aconstant int x = 10;
Bconst int x = 10;
Cint const x = 10;
DBoth B and C
Correct Answer:
D. Both B and C
Explanation:
Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare a constant in C. The const keyword can be placed before or after the type specifier, and both have the same meaning.