Array and Pointer

Question 1
Consider the following ANSI C code segment:
 z=x + 3 + y-> f1 + y-> f2;
for (i = 0; i < 200; i = i + 2) 
{
    if (z > i) 
    {
        p = p + x + 3;
        q = q + y-> f1;
    } else 
    {
        p = p + y-> f2;
        q = q + x + 3;
    }
}
Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y -> f1 or y -> f2) in the optimized code, respectively, are:
A
403 and 102
B
203 and 2
C
303 and 102
D
303 and 2
GATE CSE 2021 SET-2   C Programming
Question 2
Consider the following ANSI C program.
 #include < stdio.h >
int main( ) 
{
    int arr[4][5];
    int  i, j;
    for (i=0; i < 4; i++) 
  {
        for (j=0; j < 5; j++) 
        {
            arr[i][j] = 10 * i + j;
        }
    }
    printf("%d", *(arr[1]+9));
    return 0;
}
What is the output of the above program?
A
14
B
20
C
24
D
30
GATE CSE 2021 SET-2   C Programming
Question 3
Following declaration of an array of struct, assumes size of byte, short, int and long are 1,2,3 and 4 respectively. Alignment rule stipulates that n byte field must be located at an address divisible by n, the fields in the struct are not rearranged, padding is used to ensure alignment. All elements of array should be of same size.
 Struct complx
       Short s
       Byte b
       Long l
       Int i
End Complx
Complx C[10]
Assuming C is located at an address divisble by 8, what is the total size of C, in bytes?
A
150
B
160
C
200
D
240
ISRO CSE 2020   C Programming
Question 3 Explanation: 
NOTE: This question is Excluded for evaluation.
Click here for detail solution by gateoverflow
Question 4
What is output of the following 'C' code assuming it runs on a byte addressed little endian machine?
 #include < stdio.h >
int main()
{
    int x;
    char *ptr;
    x=622,100,101;
    printf("%d",(*(char *)&x)*(x%3));
    return 0;
}
A
622
B
311
C
22
D
110
ISRO CSE 2020   C Programming
Question 5
What is the output of the code given below?
 #include < stdio.h >
int main()
{
    char name[]="satellites";
    int len;
    int size;
    len= strlen(name);
    size = sizeof(name);
    printf("%d",len*size);
    return 0;
}
A
100
B
110
C
40
D
44
ISRO CSE 2020   C Programming
Question 6
Consider the following C program.
    #include < stdio.h >
    int main ()  {
        int  a[4] [5] = {{1, 2, 3, 4, 5},
                        {6, 7,8, 9, 10},
                        {11, 12, 13, 14, 15},
                        {16, 17,18, 19, 20}};
        printf("%d\n", *(*(a+**a+2)+3));
        return(0);
    }
The output of the program is _______.
A
7
B
10
C
18
D
19
GATE CSE 2020   C Programming
Question 7
Consider the following C program:

#include < stdio.h >
int main() { 
  int a[] = {2, 4, 6, 8, 10}; 
  int i, sum = 0, *b = a + 4; 
  for (i = 0; i < 5; i++ ) 
  sum = sum + (*b - i) - *(b - i); 
  printf("%dn", sum); 
  return 0; 
} 
The output of above C program is __________ . Note: This was Numerical Type question.
A
30
B
10
C
12
D
18
GATE CSE 2019   C programming
Question 8
Consider the following C program:

#include < stdio.h >
 int main(){
  int arr[] = {1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip = arr + 4;
  printf("%dn", ip[1]);
  return 0;
}
The number that will be displayed on execution of the program is _________ .
A
2
B
5
C
4
D
6
GATE CSE 2019   C Programming
Question 9
Consider the following declaration :
 structaddr {
    char city[10];
    char street[30];
    int pin;
};
struct {
    char name[30];
    int gender;
    struct addr locate;
} person, *kd = &person;
Then ^{\star}(k d->\text { name }+2) can be used instead of:
A
person.name+2
B
k d->(\text { name }+2)
C
*((* k d) . \text { name }+2)
D
either (A) or(B), not (C)
ISRO CSE 2018   C Programming
Question 10
Consider the following program
{
    int x=1;
    printf("%d",(*char(char*)&x));
} 
Assuming required header files are included and if the machine in which this program is executed is little endian, then the output will be
A
0
B
99999999
C
1
D
unpredictable
ISRO CSE 2018   C Programming
There are 10 questions to complete.

2 thoughts on “Array and Pointer”

  1. Sir, in the code of ques number 27, an euall to “=” sign is missing from the 5th line. It shoul be int *pi = &i;

    Reply

Leave a Comment

Like this FREE website? Please share it among all your friends and join the campaign of FREE Education to ALL.