tags:

views:

125

answers:

3
char * a=0;
int * b=0;
cout<<a<<a+1;
cout<<b<<b+1;

what's wrong with it

+1  A: 

You are assigning null (0) to the value of your pointers, which means they do not reference a valid memory location.

ElectricDialect
+8  A: 

The initializations are fine. Doing pointer arithmetic on NULL pointers is wrong.

Also, cout << (const char*) assumes the operand is a valid C-style string, not a NULL pointer. If you want to print the address of the string, not the string itself, you'll need to cast it because otherwise char pointers receive special treatment.

char* a = 0;
std::cout << static_cast<void*>(a);
UncleBens
A: 

Nothing wrong with it.

maybe something's wrong with what you expect of this code.

Pavel Radzivilovsky