help me my code has error

–3 votes
asked Oct 14 by Pallavi Priya (110 points)

My code has a error(c)

"Segmentation fault (core dumped) exit code=139"
my code=

//two syntax of declaring a pointer
#include int main() {
//syntax one
int c;
int *p = &c;
//result one
printf("%d", *p);
//syntax two
int* pc, b;
b = 5;
printf("%d", *pc);
return 0;

3 Answers

+3 votes
answered Oct 17 by Warisha Laique (320 points)
// syntax two

int* pc, b;


0 votes
answered Oct 20 by Mansi Chaurasia (140 points)
The pointer pc must point to something. I think you have missed pointing pc to b.

it should have been:

int *pc=&b;


0 votes
answered Oct 25 by Ayesha Saniya (140 points)
The program should be:


int main()


 int *ptr;

int  b;




return 0;


 Then the output will be 5
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.