943,906 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 503
  • C++ RSS
Apr 18th, 2008
0

Segmentation Fault (Tiny Program)

Expand Post »
Hi,

I'm getting seg fault in this

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. char *p;
  6. *p='w';
  7. std::cout<<p;
  8. return 0;
  9. }

I'm sure it is due to the line
C++ Syntax (Toggle Plain Text)
  1. *p='w';

I interpret this line as
Quote ...
Value at address p = 'w'
. I would like to hear an explanation on why I can't do this.

Thanks for your time
Similar Threads
Reputation Points: 15
Solved Threads: 2
Junior Poster in Training
Google Spider is offline Offline
53 posts
since Feb 2008
Apr 18th, 2008
2

Re: Segmentation Fault (Tiny Program)

>I would like to hear an explanation on why I can't do this.
Because you never told p where to point. Thus, it could point anywhere, and "anywhere" is very likely outside of your address space.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 18th, 2008
0

Re: Segmentation Fault (Tiny Program)

Thanks
Reputation Points: 15
Solved Threads: 2
Junior Poster in Training
Google Spider is offline Offline
53 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C or C++ equiv. to Python's expanduser, abspath, normpath
Next Thread in C++ Forum Timeline: Visual Studio Enterprise C++ 9.0 compatibility





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC