Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
my input to the program=68

error: segmentaion fault(core dumped)

Why I am getting this error here?

What I have tried:

C++
#include<stdio.h>
int main()
{
    int c;
    scanf("%d",c);
    putchar(c);
    return 0;
}
Posted
Updated 25-Apr-21 19:34pm

1 solution

Why do you think?

Your previous questions were good ones - but this is obvious, and related to answers you already have.

Think about it: what does c contain?
What does scanf expect you to pass?

Hint: what happens if you pass an uninitialized value to a function expecting a pointer?
 
Share this answer
 
Comments
CPallini 26-Apr-21 2:06am    
5.
_-_-_-me 26-Apr-21 2:11am    
It is because I did not pass address of the variable (pointer) to the scanf() function , I passed the variable itself.
I got it now.
Thank you.
In hint,
what happens if you pass an uninitialized value to a function expecting a pointer?
My Imagination:
I passed the variable x(auto variable) to the scanf() function. As this is auto variable, it contains some garbage value . This garbage value points to something which is not created at all.It points to something in which there is no memmory for it. So, we get error as segmentation fault(core dumped). This is the error we get when we tried to access the memmory that you do not have access to .
Is this correct?
Thank you!!!
OriginalGriff 26-Apr-21 2:19am    
That's exactly it!
Well done - excellent reasoning! :thumbsup:

I'll upvote your question, since I can't upvote your comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900