Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

44 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–44 of 44
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.41 Hard C Programming
What is the output of the following C code?
#define MAX 5
int main() {
int arr[MAX];
printf("%d", sizeof(arr)/sizeof(arr[0]));
return 0;
}
A Compilation error
B 5
C 20
D 4
Correct Answer:  B. 5
EXPLANATION
Step 1: sizeof(arr) = 5 × sizeof(int) = 20 bytes (assuming 4-byte int). Step 2: sizeof(arr[0]) = sizeof(int) = 4 bytes. Step 3: 20 ÷ 4 = 5. This calculates the number of elements in the array.
Test
Q.42 Hard C Programming
Consider the following C code. What will be printed?
int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
int *ptr = (int *)arr;
printf("%d", *(ptr + 5));
A 5
B 6
C 8
D 9
Correct Answer:  B. 6
EXPLANATION

A 2D array is stored in row-major order in memory: 1,2,3,4,5,6,7,8,9. When ptr is cast to int*, ptr+5 points to the 6th element (0-indexed), which is 6.

Test
Q.43 Hard C Programming
What is the correct way to declare a constant pointer to a constant integer?
A const int * const ptr;
B const int const *ptr;
C int const * const ptr;
D Both A and C
Correct Answer:  D. Both A and C
EXPLANATION

Both declarations are equivalent. 'const int * const ptr' and 'int const * const ptr' declare a constant pointer to a constant integer. The first const makes the integer constant, the second const makes the pointer constant.

Test
Q.44 Hard C Programming
What is the output of the following C code?
#include
int main() {
int a = 5;
printf("%d %d %d", a++, ++a, a);
return 0;
}
A 5 7 7
B 6 7 7
C 5 6 6
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

This code contains undefined behavior because variable 'a' is modified multiple times (a++, ++a) without intervening sequence points in the same expression. The order of evaluation is unspecified, making the result compiler-dependent.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips