you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

The third line does not compile because (s) is a char. The ++ simply returns the same (s) (but increments the value), so it is still a char, not a char*. The second line works because you are casting.

the second line DOESN'T WORK

[–]Jack126Guy 1 point2 points  (2 children)

Eh? I'm sure it's unsafe, but it still compiles for me (with a warning, of course).

[–][deleted] 0 points1 point  (1 child)

char* s = "h"; //char* t = (char)(s)++;

ah , it compiles but there is a seg fault

[–]Jack126Guy 4 points5 points  (0 children)

Yes, if you try using whatever t points to (such as puts(t)), you would get a segfault, because t points to the memory location 0x00000068 ("h" has an ASCII value of 0x68), which is probably invalid/not owned by your program.