Skip to content

Listing 3-7 #30

@aroeiraio

Description

@aroeiraio

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";
5.
6.     char* upper_ptr = &upper[0];
7.     *(lower + 3) = 'd';
8.     *(upper_ptr + 3) = 'D';
9.
10.    char letter_d = *(lower + 4); // lower decays into a pointer when we add
11.    char letter_D = *(upper_ptr + 4);
12.
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions