# 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[3][3][3] =
{{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[2] = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z[1];
*(&z[0]+1)+=3;
printf("%d, %d, %d \n",x,z[0],z[1]); 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[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 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[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 5 Explanation:
NOTE: This question is Excluded for evaluation.