GATE 2000
54 questions
MCQ 541-mark 54
Questions 26–30 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.
Suppose you are given an array s[1....n] and a procedure reverse (s, i, j) which reverses the order of elements in s between positions i and j (both inclusive). What does the following sequence do, where 1 n:
reverse (s, 1, k);
reverse (s, k+1, n);
reverse (s, 1, n); Answer: (A)
Split into two parts: , the first elements, and , the remaining elements. So .
- turns it into .
- turns it into .
- reverses the whole array, giving .
is rotated left by places, for any from 1 to .
Example with and :
- gives
- gives
- gives
The array is rotated left by 2 places.
Answer: (A)
- turns it into .
- turns it into .
- reverses the whole array, giving .
is rotated left by places, for any from 1 to .
Example with and :
- gives
- gives
- gives
The array is rotated left by 2 places.
Answer: (A)