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 10 of 11.
LOÃS said:
10 years ago
When one write char ***p; p is adress of an array of char;
i.e:
char *s[]={"white", "pink", "violet", "black"}; // s is an array of char who is equal to char **s.
If you want a pointer to point on that array you will declare it as char ***ptr=&s and then:
ptr--->&s;--->@@white
*ptr---->s;--->@white
**ptr---->*s--->white
**ptr+1--->*s+1--->hite
Now look at Akshay Kalra concept, it's very clear.
i.e:
char *s[]={"white", "pink", "violet", "black"}; // s is an array of char who is equal to char **s.
If you want a pointer to point on that array you will declare it as char ***ptr=&s and then:
ptr--->&s;--->@@white
*ptr---->s;--->@white
**ptr---->*s--->white
**ptr+1--->*s+1--->hite
Now look at Akshay Kalra concept, it's very clear.
Xyz said:
10 years ago
What is the output if we put %c instead of %s in printf statement?
Emanuel said:
10 years ago
I think it doesn't work.
The 1st line keeps the array of char pointers. The array of addresses of the first team of each char array, and who will keep the each char array itself?
Correct me, if I am wrong.
The 1st line keeps the array of char pointers. The array of addresses of the first team of each char array, and who will keep the each char array itself?
Correct me, if I am wrong.
Emanuel said:
10 years ago
I think the name of the array is a pointer to the 1st method of the array, but when it is stated implicitly how it can be catched by a pointer to char?
SelvaKarna said:
10 years ago
How to print white?
black?
pink?
Can any one tell me?
black?
pink?
Can any one tell me?
Manish said:
10 years ago
Not getting, please explain me clearly.
Prasanth said:
10 years ago
Thank you @Radhakrishna.
Travy said:
9 years ago
Please, tell me, why we are using **p+1 in printf? What's the concept?
I know it will print ink but what's the use of using **p instead of p+1?
Here we have set p=ptr, someone please help me out.
I know it will print ink but what's the use of using **p instead of p+1?
Here we have set p=ptr, someone please help me out.
Vasu said:
9 years ago
If we want to print **++*__p what will be the answer? Please explain it.
Danish said:
9 years ago
Best explanation, Thanks, @Piyush Prakash.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers