I was recently asked this question in an interview:
char* p = NULL;
cout << p << endl;
++p;
cout << p << endl;
I gave the answer that first cout will print 00000, next will print 00001. But when I checked it in visual studio, it gives an exception: First-chance exception at 0x009159F1 in StringFunctions.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x009159F1 in StringFunctions.exe: 0xC0000005: Access violation reading location 0x00000000.
But it works as expected for int, float etc. Could anybody explain this? Appreciate the help!