Int Int: #Include
Int Int: #Include
1. #include <stdio.h>
2. int main () {
3. int a[4] [5] = {{1, 2, 3, 4, 5},
4. {6, 7,8, 9, 10},
5. {11, 12, 13, 14, 15},
6. {16, 17,18, 19, 20}};
7. printf(“%d\n”, *(*(a+**a+2)+3));
8. return(0);
9. }
Ans
a=a= address of 0th0th index 1-D array
∗∗a=1∗∗a=1
∗∗a+2=1+2=3∗∗a+2=1+2=3
GATE-2005
1. A program P reads in 500 integers in the range [0,100] representing the scores of
500 students. It then prints the frequency of each score above 50. what would be
the best way for P to store the frequencies?
GATE-2000
2. An n*n array V is defined as follows
V[i,j]=i-j for all i,j, 1<=i<=n;1<=j<=n;
The sum of the elements of the array V is
(a) 0 (b) n-1 (c) n2-3n+2 (d) n2(n+1)/2
GATE-2000
3. Suppose you are given an array s[1...n] and a procedure reverse (s,i,j) which
reverse the order of elements in s between positions i and j (both inclusive). What
does the following sequence do, where 1 < k <= n:
reverse (s, 1, k);
reverse (s, k + 1, n);
reverse (s, 1, n);
(a) Rotates s left by k positions
(b) Leaves s unchanged
(c) Reverses all elements of s
(d) None of the above
GATE-2004
4. A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks
grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point
to the location of the topmost element in each of the stacks. If the space is to be
used efficiently, the condition for “stack full” is
(a) (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
(b) top1 + top2 = MAXSIZE
(c) (top1= MAXSIZE/2) or (top2 = MAXSIZE)
(d) top1= top2 -1
Ans: option(a)
Explanation:
The array is stored in row-major order, that means the elements are stored in the
memory row-wise.
Suppose we have the 2D array
123
456
It will be stored in the memory as 1 2 3 4 5 6
If array is stored as column-major order then it will be stored as 1 4 2 5 3 6
L - base address of the array, i.e. address of the first element of the array
M - Memory Size, here each integer takes only 1 memory location therefore M = 1
Note:
To find the location of A[i][j] for a 2D array stored in Column-major order use the
following formula:
GATE-1994
7. In a compact single dimensional array representation for lower
triangular matrices (i.e all the elements above the diagonal are zero) of size n x n ,
non-zero elements (i.e elements of the lower triangle) of each row are stored one
after another, starting from the first row, the index of the (i,j)th element of the
lower triangular matrix in this new representation is:
(a) i + j (b) i + j -1 (c) j + [i(i-1)/2] (d) i + [j(j-1)/2]