Array and Pointer · Programming in C
54 questions · asked in 22 of 27 years (2000–2026)
MCQ 39 · MSQ 1 · NAT 141-mark 34 · 2-mark 20
2000Questions per year2026
Questions 51–54 of 54
Consider the following C declaration:
Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is:
struct {
short x[5];
union {
float y;
long z;
} u;
} t; Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is:
Answer: (C)
Let us go through each member:
- The array short x[5] takes 5 2 = 10 bytes.
- The union takes the size of its biggest member. That is long, which is 8 bytes.
So the total is 10 + 8 = 18 bytes.
Answer: 18 bytes
- The array short x[5] takes 5 2 = 10 bytes.
- The union takes the size of its biggest member. That is long, which is 8 bytes.
So the total is 10 + 8 = 18 bytes.
Answer: 18 bytes
Aliasing in the context of programming languages refers to
Answer: (A)
The correct option is .
In programming, aliasing means the same memory location can be reached through different names. For example, a function gets two pointers and that hold the same value. Then the name aliases the name
The most appropriate matching for the following pairs is:
Answer: (D)
X: The only pointer to the allocated block is overwritten with NULL. The block is still allocated but nobody can reach it or free it. This is lost memory (3).
Y: After free, still holds the old address, which is no longer valid, and the next statement writes through it. This is a dangling pointer (1).
Z: was never given an address, but the program stores through it. This is an uninitialized pointer (2).
So X-3, Y-1, Z-2.
Answer: (D)
Y: After free, still holds the old address, which is no longer valid, and the next statement writes through it. This is a dangling pointer (1).
Z: was never given an address, but the program stores through it. This is an uninitialized pointer (2).
So X-3, Y-1, Z-2.
Answer: (D)
The following C declarations:
struct node {
int i;
float j;
};
struct node *s[10]; define s to be:Answer: (A)
Correct Option: A
In C, the operator is higher in precedence than . Because of this, is an array of pointers.
Keep practising