Pointer arithmetic for structs

后端 未结 5 2235
鱼传尺愫
鱼传尺愫 2021-02-07 08:02

Given a struct definition that contains one double and three int variables (4 variables in all), if p is a pointer to this struct with a value 0x1000, what value does p++ have?<

5条回答
  •  眼角桃花
    2021-02-07 08:56

    struct foobar *p;
    p = 0x1000; 
    p++;
    

    is the same as

    struct foobar *p;
    p = 0x1000 + sizeof(struct foobar);
    

提交回复
热议问题