# Array and Pointer

 Question 1
What is printed by the following ANSI C program?
``````#include < stdio.h >
int main(int argc, char *argv[])
{
int a =
{{1, 2, 3, 4, 5, 6, 7, 8, 9},
{10, 11, 12, 13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24, 25, 26, 27}};
int i = 0, j = 0, k = 0;
for( i = 0; i < 3; i++ ){

for(k = 0; k < 3; k++ )
printf("%d ", a[i][j][k]);
printf(" \n");
}
return 0;
}
``````
 A 1 2 3 10 11 12 19 20 21 B 1 4 7 10 13 16 19 22 25 C 1 2 3 4 5 6 7 8 9 D 1 2 3 13 14 15 25 26 27
GATE CSE 2022   C Programming
Question 1 Explanation:
 Question 2
What is printed by the following ANSI C program?
``````
#include < stdio.h >
int main(int argc, char *argv[])
{
int x = 1, z = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z;
*(&z+1)+=3;
printf("%d, %d, %d \n",x,z,z); return   0;
}
``````
``` ```
 A 1, 10, 11 B 1, 10, 14 C 10, 14, 11 D 10, 10, 14
GATE CSE 2022   C Programming
Question 2 Explanation:
 Question 3
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 3 Explanation:
 Question 4
Consider the following ANSI C program.
`````` #include < stdio.h >
int main( )
{
int arr;
int  i, j;
for (i=0; i < 4; i++)
{
for (j=0; j < 5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr+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 4 Explanation:
 Question 5
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``````
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 5 Explanation:
NOTE: This question is Excluded for evaluation.
Click here for detail solution by gateoverflow
 Question 6
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 6 Explanation:
 Question 7
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 7 Explanation:
 Question 8
Consider the following C program.
``````    #include < stdio.h >
int main ()  {
int  a  = {{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 8 Explanation:
 Question 9
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 9 Explanation:
 Question 10
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);
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 10 Explanation:
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;

• 