Array and Pointer


Q41.

Consider the following C program which is supposed to compute the transpose of a given 4 \times 4 matrix M. Note that, there is an X in the program which indicates some missing statements. Choose the correct option to replace X in the program. #include < stdio.h > #define ROW 4 #define COL 4 int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; main() { int i, j, t; for (i = 0; i < 4; ++i) { X } for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) printf ("%d", M[i][j]); }
GateOverflow

Q42.

In the following C program fragment, j, k, n and TwoLog_n are integer variables, and A is an array of integers. The variable n is initialized to an integer \geq 3, and TwoLog_n is initialized to the value of 2*\left \lceil log_{2}n \right \rceil for (k = 3; k < = n; k++) A[k] = 0; for (k = 2; k < = TwoLog_n; k++) for (j = k + 1; j < = n; j++) A[j] = A[j] || (j % k); for (j = 3; j < = n; j++) if (!A[j]) printf("%d", j); The set of number printed by this program fragment is
GateOverflow

Q43.

Assume the following C variable declaration int *A [10], B[10][10]; Of the following expressions I A[2] II A[2][3] III B[1] IV B[2][3] which will not give compile-time errors if used as left hand sides of assignment statements in a C program?
GateOverflow

Q44.

Consider the following C declaration: 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:
GateOverflow

Q45.

Aliasing in the context of programming languages refers to
GateOverflow

Q46.

The most appropriate matching for the following pairs is: \begin{array}{|ll|ll|}\hline X: & \text{m = malloc(5); m = NULL;} & 1: & \text{using dangling pointers} \\\hline Y: & \text{free(n); n -> value = 5;} & 2: & \text{using uninitialized pointers} \\\hline Z: & \text{char *p , *p = 'a' ; } & 3: & \text{lost memory} \\\hline \end{array}
GateOverflow

Q47.

The following C declarations: struct node { int i: float j; }; struct node *s[10]; define s to be:
GateOverflow

Q48.

Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0. i = 0; j = 1; while (j < n ){ if (E) j++; else if (a[j] - a[i] == S) break; else i++; } if (j < n) printf("yes") else printf ("no"); Choose the correct expression for E.
GateOverflow

Q49.

The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s. int anagram (char *a, char *b) { int count [128], j; for (j = 0; j < 128; j++) count[j] = 0; j = 0; while (a[j] && b[j]) { A; B; } for (j = 0; j < 128; j++) if (count [j]) return 0; return 1; } Choose the correct alternative for statements A and B.
GateOverflow