Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing 3-7 #30

carpajr opened this issue Oct 23, 2019 · 1 comment

Listing 3-7 #30

carpajr opened this issue Oct 23, 2019 · 1 comment


Copy link

@carpajr carpajr commented Oct 23, 2019

Hello, Josh!

At example 3-7, I found something that I have a question.

1. #include <cstdio>
2. int main() {
3.     char lower[] = "abc?e";
4.     char upper[] = "ABC?E";
6.     char* upper_ptr = &upper[0];
7.     *(lower + 3) = 'd';
8.     *(upper_ptr + 3) = 'D';
10.    char letter_d = *(lower + 4); // lower decays into a pointer when we add
11.    char letter_D = *(upper_ptr + 4);
13.    printf("lower: %s\nupper: %s", lower, upper);
14.    *(lower + 7) = 'g';
15. }

The lines 10 and 11 points to offset 4, but I think the offset is 3. What do you think?

I have to mention that your book is fantastic! It has been a long time since I had found such an enjoyable approach. I have to say that your book became a bedside book. Thanks for your excellent work!

Regards from Brazil

Copy link

@JLospinoso JLospinoso commented Oct 23, 2019

Hi @carpajr, you are absolutely correct. Thanks very much for reporting! I really hope you enjoy the rest of the book :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants