What is the output for the following program

main()

{

int arr2D[3][3];

printf("%d\n", ((arr2D==* arr2D)&&(* arr2D ==
arr2D[0])) );

}



What is the output for the following program main() { ..

Answer / susie

Answer :

1

Explanation

This is due to the close relation between the arrays and
pointers. N dimensional arrays are made up of (N-1)
dimensional arrays.

arr2D is made up of a 3 single arrays that contains 3
integers each .

The name arr2D refers to the beginning of all the 3 arrays.
*arr2D refers to the start of the first 1D array (of 3
integers) that is the same address as arr2D. So the
expression (arr2D == *arr2D) is true (1).

Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero
doesn’t change the value/meaning. Again arr2D[0] is the
another way of telling *(arr2D + 0). So the expression
(*(arr2D + 0) == arr2D[0]) is true (1).

Since both parts of the expression evaluates to true the
result is true(1) and the same is printed.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Code Interview Questions

String reverse with time complexity of n/2 with out using temporary variable.

10 Answers   NetApp, Symantec,


#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


String copy logic in one line.

11 Answers   Microsoft, NetApp,


{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

4 Answers  


print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!!

35 Answers   Tata Elxsi, TCS, VI eTrans,






union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0

1 Answers   HCL,


#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


write a program to count the number the same (letter/character foreg: 's') in a given sentence.

2 Answers  


main() { char not; not=!2; printf("%d",not); }

1 Answers  


There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }

1 Answers  


Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

1 Answers  


main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

3 Answers  


Categories