C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 2)
2.
What will be the output of the program ?
#include<stdio.h>
int main()
{
static int a[2][2] = {1, 2, 3, 4};
int i, j;
static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),
*(*(i+p)+j), *(*(p+j)+i));
}
}
return 0;
}
Discussion:
78 comments Page 7 of 8.
Nikhil said:
8 years ago
Please explain this question how the compiler works?
Manoja V. said:
8 years ago
Thank you @Dilip.
Preethi said:
8 years ago
Nice Explanation @Dilip.
Arunsethupathy said:
8 years ago
Thank You @Shweta.
Som said:
8 years ago
Hi,
If the variable 'p' in printf statement is replaced by array name 'a', then we get the output as option 'A'.
Could anyone explain this discrepancy?
If the variable 'p' in printf statement is replaced by array name 'a', then we get the output as option 'A'.
Could anyone explain this discrepancy?
Raadhi said:
7 years ago
Thank you @Dilip.
Raadhi said:
7 years ago
Thank you @Dilip.
Raadhi said:
7 years ago
Thank you @Dilip.
Venkat said:
7 years ago
Thanks @Pradeepa.
(1)
Jhanu said:
7 years ago
Thank you @Dilip.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers