0

Hi,

I'm getting seg fault in this

#include <iostream>

int main()
{
	char *p;
	*p='w';
	std::cout<<p;
	return 0;
}

I'm sure it is due to the line

*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

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Google Spider
1

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

Votes + Comments
Coz she helped me with my dumb question*
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.