C Programming


Q1.

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; }
GateOverflow

Q2.

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; }
GateOverflow

Q3.

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; }
GateOverflow

Q4.

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?
GateOverflow

Q5.

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; }
GateOverflow

Q6.

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 _______.
GateOverflow

Q7.

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.
GateOverflow

Q8.

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 _________ .
GateOverflow

Q9.

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
GateOverflow

Q10.

Consider the following C program. #include < stdio.h > struct Ournode{ char x,y,z; }; int main(){ struct Ournode p = {'1', '0','a'+2}; struct Ournode *q = &p printf("%c,%c",*((char*)q+1),*((char*)q+2)); return 0; } The output of this program is:
GateOverflow