C++ 指针的偏移 The offset of a pointer in C++
来源:互联网 发布:简述js闭包使用场景 编辑:程序博客网 时间:2024/06/06 01:43
A problem from my friend, what's the result of the following code:
class str{public: int x; char s[0];};class foo{public: str * p;};int main() { foo f = {0}; str* p1 = NULL; if (f.p->s){ printf("%d\n", f.p->s); } return 0;}
This sentence sets p to NULL:
foo f = {0};
f.p is a pointer of str, so f.p is an offset. I.e., f.p->s = base address + 4
So the result is 4
2 0
- C++ 指针的偏移 The offset of a pointer in C++
- The amazing efficiency of pointer in C Programming Language
- c++: the hint of pointer
- What are the differences between a pointer variable and a reference variable in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- How to use the pointer of function in a class?
- C指针偏移量
- Mad Pointer in C
- Pointer in C/C++
- 得到文件某行的偏移量(get byte offset of a line)
- the type of a pointer
- Function Pointer of class member function C++的类成员函数指针简要
- type conversion of array and pointer in C(1)
- type conversion of array and pointer in C(2)
- How to set NULL to a pointer in Managed C++?
- C++:智能指针(Smart Pointer)
- 【C++】智能指针(Smart Pointer)
- C column of Pointer <0>
- 通过多线程技术提高Android应用性能
- jquery源码学习
- 双向循环链表
- 网站需要做好二次营销的几个方案才能将流量最大化
- C++基础
- C++ 指针的偏移 The offset of a pointer in C++
- SSH知识总结
- linux内核可以接受的参数 | Linux kernel启动参数 | 通过grub给内核传递参数
- 二维最大熵阈值分割原理与opencv实现
- [学习Cython编程]Cython编程入门
- ajax回调函数中$(this)没有作用的解决办法
- 设计模式之四 抽象工厂模式
- 复制和移动文件
- MyEclipse非常方便的快捷键