Sep 24, 2012 at 2:29pm UTC
Hi.
having a definition:
char *s="74\11203" ;
what does
cout << s-- << endl;
do?Thanks in advance!
Sep 24, 2012 at 2:40pm UTC
The code
cout << s-- << endl;
has undefined behaviour because a pointer shall not point beyond the first element of an array.
As for "what does it do" the statement outputs the string literal "74\11203" and decrements the pointer that results in undefined behaviour.
Last edited on Sep 24, 2012 at 2:41pm UTC
Sep 24, 2012 at 4:00pm UTC
Decrementing the pointer doesn't result in undefined behavior. Thinking of iterators, perhaps? If one were to dereference the decremented pointer, however...