Segmentation Fault (Tiny Program)

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 53
Reputation: Google Spider is an unknown quantity at this point 
Solved Threads: 2
Google Spider's Avatar
Google Spider Google Spider is offline Offline
Junior Poster in Training

Segmentation Fault (Tiny Program)

 
0
  #1
Apr 18th, 2008
Hi,

I'm getting seg fault in this

  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
  1. *p='w';

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

Thanks for your time
All suspects are guilty until proven innocent, other wise, they wouldn't be suspects would they?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,728
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Segmentation Fault (Tiny Program)

 
2
  #2
Apr 18th, 2008
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 53
Reputation: Google Spider is an unknown quantity at this point 
Solved Threads: 2
Google Spider's Avatar
Google Spider Google Spider is offline Offline
Junior Poster in Training

Re: Segmentation Fault (Tiny Program)

 
0
  #3
Apr 18th, 2008
Thanks
All suspects are guilty until proven innocent, other wise, they wouldn't be suspects would they?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC