0

Isn't the line 1 and line 4 means the same that is in *ptr and hello both contain manash so why hello runs but *ptr doesn't?

#include <stdio.h> #include <string.h> int main(){ char hello[] = "manash"; char * ptr = &hello; printf("%s\n",hello); printf("%s\n",ptr); printf("%s\n",&hello); printf("%s\n",*ptr); return 0;}

3rd Nov 2021, 11:03 AM
Manash Anand
Manash Anand - avatar
4 Respuestas
+ 2
#include <stdio.h> #include <string.h> int main(){ char hello[] = "manash"; char * ptr = hello; //no need of & since it is charecter array, already points to starting addrress printf("%s\n",hello); //%s prints total array printf("%s\n",ptr); printf("%p\n",&hello); // &hello returns address of hello array.. printf("%c\n",*ptr); //*ptr points to the value of first charecter array , not total array. and ptr returns total array. return 0; } //hope it helps...
3rd Nov 2021, 11:32 AM
Jayakrishna 🇮🇳
+ 1
There *ptr returns a single first charecter so need %c ..
3rd Nov 2021, 3:34 PM
Jayakrishna 🇮🇳
0
Okay I got your point so does that mean Printf("%c\n,*ptr); gives output m My coding c app give me error but it's okay if It atleast give me m as an output
3rd Nov 2021, 1:30 PM
Manash Anand
Manash Anand - avatar
0
Ooo the small details You Gotcha me Well thanks for the help!
3rd Nov 2021, 4:28 PM
Manash Anand
Manash Anand - avatar