in Programming in C
1,459 views
1 vote
1 vote

Anyone kindly tell the reason why the outputs are differ ?

#include<stdio.h>

int main()

{

 char *ptr = "geeksforgeeks";

 printf("%c\n", *&*&*ptr);

   

 getchar();

 return 0;

}

Output-g

 

#include<stdio.h>

int main()

{

 char *ptr = "geeksforgeeks";

 printf("%s\n", *&*&ptr);

   

 getchar();

 return 0;

}

Output-geeksforgeeks

in Programming in C
1.5k views

2 Answers

1 vote
1 vote

......

2 Comments

ohk i mdified a program a bit in second question *&*&*ptr is gave segmentation fault.could you pls tell why this?
0
0

Summary of ur question

#include<stdio.h>
int main()
{
 char *ptr = "geeksforgeeks";
 printf("%s\n", *ptr);
 return 0;
}

*ptr means value at that location, it cannot be a string. Value at a location can only be a character. But u want to print total string. That is why it is giving segmentation fault

1
1
0 votes
0 votes
Because you are printing as string in second one if u put %c then the answer would be g again

Related questions