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

Recommended Answers

All 2 Replies

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

commented: Coz she helped me with my dumb question* +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.