4
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by jnawrocki
2

Try it, it won't bite you. ;)

To learn to be a problem solver, you have to explore the world of code - roses and thorns, as well.

Edited by Adak: n/a

Votes + Comments
I also agree.
agree
0

If I am not mistaken, It will probably crash the program.
1.)The space for the pointer p was not allocated from the system. This means it does not belong to you.
2.)Declaring main with (or without void), is undefined behavior, you should use int main().

You are incrementing the value of a char, so you are changing the encoded value. For example a may be represented as 100 for computers b as 101 and c as 102. So if you increment 3 times you may get c (it depends if they are in order. 103 for example may represent something completely different). You can express it as ++(++(++p)). If p is a, then this statement should be c. But if you add 3 to a, the compiler will probably convert a to integer so you will get number outputted to the screen.

You can also use typecasting (variable type). For example if you try to output (char)101, you should get e (or it may be another character).

Edited by sergent: n/a

0

First the post-increment p++ has no effect because it happens after the function.

Second ”,++*(p)); // got rid of post-increment but still invalid memory write and system crash.

If you want to print the second character and, for some reason, do not want to code the standard p[1], then move the pre-increment so it associates with with p. In other words ”,*(++p)

Edited by jnawrocki: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.