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;
}
ink
ack
ite
let
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
110 comments Page 5 of 11.

Venkadesh said:   1 decade ago
I run this program in the turbo C++. But I get the output as " nk " . can anyone tell me why?. The code is,

static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);

Mayank jain said:   1 decade ago
The second line char **ptr[] = {s+3,s+2,s+1,s};

Reverse the original string whose first element is violet and pointed by *ptr.

Then ++p made it to point pink(second element).

At last **p+1 points to the string from second alphabet of 'pink'.

T.saipavan said:   1 decade ago
Why pointers are to be used?

Prakash said:   1 decade ago
To access the elements efficiently in different methodologies and execution speed is faster.

U Naveena Reddy said:   1 decade ago
What is the use of ** (double star) , *** (triple stars) , if you don't mind, please explain me?

Nani said:   1 decade ago
What is the value of *ptr and ptr in the program? please give me the explanation?

Swati said:   1 decade ago
What does **ptr and ***ptr means? why do we use them? can someone please explain?

Sumathi said:   1 decade ago
main(){int x=2,p*,q*;
p=q=&x;
*q+=*p+=a+=4;
printf("%d%d%d",x,*p,*q);
}

The output of this program is x=24 *p=24 *q=24.
I can't understand the program. Will anyone please explain this program?

Manali said:   1 decade ago
Hey anybody can tell me exact meaning of more than one * sign?

Prem said:   1 decade ago
Hi, @Manali.

*k = value at the address contained in k.
**k = value at the address contained in *k.

And so on...


Post your comments here:

Your comments will be displayed after verification.