摘要:
Byte Endian是指字节在内存中的组织,所以也称它为Byte Ordering,或Byte Order。对于数据中跨越多个字节的对象, 我们必须为它建立这样的约定:(1) 它的地址是多少?(2) 它的字节在内存中是如何组织的?针 对第一个问题,有这样的解释: 对于跨越多个字节的对象,一般它所占的字节都是连续的,它的地址等于它所占字节最低地址。(链表可能是个例外,但链表的地址可看作链表头的地址)。比如: int x, 它的地址为0x100。 那么它占据了内存中的0x100, 0x101, 0x102, 0x103这四个字节(32位系统,所以int占用4个字节)。上面只是内存字节组织的一种情 阅读全文
摘要:
从后往前初始化,例如下例中,首先初始化n1,因为用n2+2来初始化n1,所以n1的值为不确定;而n2稍后被初始化为0。#include <iostream>using namespace std;class A{private: int n1; int n2;public: A() : n2(0), n1(n2 + 2) {} void Print(){cout<<n1<<endl<<n2<<endl;}};int main(){ A a; a.Print(); return 0;}EOF 阅读全文