C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 1)
1.
What will be the output of the program ?
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
Discussion:
110 comments Page 8 of 11.
Shalu said:
1 decade ago
I want answer of printf("%s, *--*++p+3).
Prithvi Shankar said:
1 decade ago
I still don't understand the difference between ** and * and ***. How do we say that by having ** the characters of the array are accessed?
Binod said:
1 decade ago
I don't understand ***p step.
Madhav said:
1 decade ago
What is the use of static in the program?
Digvijay said:
1 decade ago
Thank you all for great explanation.
Murthy said:
1 decade ago
s is a character pointer.
s[]:
s[0]=black.
s[1]=white.
s[2]=pink.
s[3]=violet.
ptr[]:
ptr[0]=violet.
ptr[1]=pink.
ptr[2]=white.
ptr[3]=black.
Here p=ptr i.e p, ptr are the same address.
++p is equal to ++ptr that means pink. For these p++ ia added the +1 that means ++p+1 that is **p+1 means ink.
s[]:
s[0]=black.
s[1]=white.
s[2]=pink.
s[3]=violet.
ptr[]:
ptr[0]=violet.
ptr[1]=pink.
ptr[2]=white.
ptr[3]=black.
Here p=ptr i.e p, ptr are the same address.
++p is equal to ++ptr that means pink. For these p++ ia added the +1 that means ++p+1 that is **p+1 means ink.
Bhas said:
1 decade ago
How **p+1 means ink?
Bhavya kp said:
10 years ago
It refers second variable. And also gives output from second word of referred variable.
Dipali said:
10 years ago
I can't understand. Please clrealy discuss.
Divya said:
10 years ago
printf("%s", **p+1);
Here why we use double pointer in **p+1.
What will happen, if we use single pointer like *p+1.
Here why we use double pointer in **p+1.
What will happen, if we use single pointer like *p+1.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers