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;
}
1 2 3
10 11 12 19 20 21 | |
1 4 7 10 13 16 19 22 25 | |
1 2 3
4 5 6 7 8 9 | |
1 2 3
13 14 15 25 26 27 |
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;
}
1, 10, 11 | |
1, 10, 14 | |
10, 14, 11 | |
10, 10, 14 |
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:403 and 102 | |
203 and 2 | |
303 and 102 | |
303 and 2 |
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?14 | |
20 | |
24 | |
30 |
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?150 | |
160 | |
200 | |
240 |
Question 5 Explanation:
NOTE: This question is Excluded
for
evaluation.
Click here for detail solution by gateoverflow
Click here for detail solution by gateoverflow
There are 5 questions to complete.
Sir, in the code of ques number 27, an euall to “=” sign is missing from the 5th line. It shoul be int *pi = &i;
Thank You Ashutosh,
We have updated the question.