Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

help me my code has error

–3 votes
asked Oct 14, 2020 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, 2020 by Warisha Laique (320 points)
// syntax two

int* pc, b;

pc=&b;

b=5;
0 votes
answered Oct 20, 2020 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;

b=5;

printf("%d",*pc);
0 votes
answered Oct 25, 2020 by Ayesha Saniya (140 points)
The program should be:

#include<stdio.h>

int main()

{

 int *ptr;

int  b;

b=5;

ptr=&b;

printf("%d",*ptr);

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.
...