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

main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

1 Answers  


Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.

3 Answers   Wipro,


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

3 Answers  


main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }

1 Answers   Zoho,


Program to Delete an element from a doubly linked list.

4 Answers   College School Exams Tests, Infosys,






how to check whether a linked list is circular.

11 Answers   Microsoft,


program to find the roots of a quadratic equation

14 Answers   College School Exams Tests, Engineering, HP, IIIT, Infosys, Rajiv Gandhi University of Knowledge Technologies RGUKT, SSC,


How to palindrom string in c language?

6 Answers   Google,


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


write the function. if all the character in string B appear in string A, return true, otherwise return false.

11 Answers   Google,


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

0 Answers  


main() { int c=- -2; printf("c=%d",c); }

1 Answers   TCS,


Categories