Array and Pointer: GATE CS Previous Year Questions

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 41–45 of 54

Q41GATE 20061 markMCQ−0.33 if wrong
Which one of the choices given below would be printed when the following program is executed?
 #include <stdio.h>
int a1[] = {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x[] = {a1, a2, a3};
void print(int *a[])
{
    printf("%d,", a[0][2]);
    printf("%d,", *a[2]);
    printf("%d,", *++a[0]);
    printf("%d,", *(++a)[0]);
    printf("%d\n", a[-1][+1]);
}
main()
{
     print(x);
}

Q42GATE 20061 markMCQ−0.33 if wrong
Which one of the choices given below would be printed when the following program is executed ?
 #include <stdio.h>
struct test {
               int i;
               char *c;
}st[] = {5, "become", 4, "better", 6, "jungle", 8, "ancestor", 7, "brother"};
main ()
{ 
    struct test *p = st;
    p += 1;
    ++p -> c;
    printf("%s,", p++ -> c);
    printf("%c,", *++p -> c);
    printf("%d,", p[0].i);
    printf("%s \n", p -> c);
}

Q43GATE 20061 markMCQ−0.33 if wrong
Consider the C code to swap two integers and these five statements: the code
 void swap(int *px,int *py){
*px=*px-*py;
*py=*px+*py;
*px=*py-*px;
}
S1 : will generate a compilation error
S2 : may generate a segmentation fault at runtime depending on the arguments passed
S3 : correctly implements the swap procedure for all input pointers referreing to integers stored in memory locations accessible tot he process
S4 : implements the swap procedure correctly for some but not all valid input pointers
S5 : may add or subtract integers and pointers

Q44GATE 20051 markMCQ−0.33 if wrong
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.

Q45GATE 20051 markMCQ−0.33 if wrong
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.

Keep practising

Topics in Programming in C

All CS topics ›