C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 5)
5.
What will be the output of the program ?
#include<stdio.h>
int main()
{
static int arr[] = {0, 1, 2, 3, 4};
int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int **ptr=p;
ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*++ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
++*ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
return 0;
}
Discussion:
38 comments Page 3 of 4.
Sri said:
10 years ago
Please give clear explanation.
Dileep said:
9 years ago
Can't understand this? Please help me to get it.
Abhishek said:
9 years ago
Thank you guys. Got it finally, special thanks to @Leenaja.
Raji said:
9 years ago
Thank you @Angel_Eyez.
HARI said:
9 years ago
How ptr points to 0? It should point to the address of first element in p.
Prashant said:
9 years ago
Hi, I am not getting this. Please, anyone explain me.
Jyoti said:
8 years ago
I don't understand.
Why takes p as 0, and then 0-array as 1?
Why takes p as 0, and then 0-array as 1?
Raji said:
8 years ago
Thank you @Leenaja.
Vishwa said:
8 years ago
#include<stdio.h>
int main()
{
int a[][2]={3,6,8,9};
printf("%d\n",a[1][-1]);
return 0;
}
I got output 6.
Can anyone explain this?
int main()
{
int a[][2]={3,6,8,9};
printf("%d\n",a[1][-1]);
return 0;
}
I got output 6.
Can anyone explain this?
Neeraj said:
8 years ago
What if the array arr is not declared as static?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers