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 4 of 8.
Manoj said:
1 decade ago
See the difference : No change.
static int *p[] = {(int*)a};//, (int*)a+1, (int*)a+2};
static int *p[] = {(int*)a};//, (int*)a+1, (int*)a+2};
Reena said:
1 decade ago
@Anushu.
The answer correct is:
1111
2222
2222
3333
The given answer is correctly.
The answer correct is:
1111
2222
2222
3333
The given answer is correctly.
Kim said:
1 decade ago
*p is an array of pointers each of wich is pointing to an element of the array a.
Lakshmi said:
1 decade ago
static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
Can you explain this step.
Can you explain this step.
Balamanikanta said:
1 decade ago
static int *p[] = {(int*)a, (int*)a+1, (int*)a+2}; please explain this step.
Abin joseph said:
1 decade ago
Thank you Mr.Chand.
I like your explanation very much.
It is very helpfull.
I like your explanation very much.
It is very helpfull.
Arun said:
1 decade ago
Why more operators are used in variable?
Does it show different meaning?
Does it show different meaning?
Manoj said:
1 decade ago
Try this code : Same output.
*(*p+i+j), *(*p+i+j), *(*p+i+j), *(*p+i+j).
*(*p+i+j), *(*p+i+j), *(*p+i+j), *(*p+i+j).
Sourabh said:
1 decade ago
What may be the answer if we solve it by as two dimensional array?
Priya said:
1 decade ago
Here we use static type 'p'.
That's why default value of p is 0.
That's why default value of p is 0.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers