关闭

指针测试之函数中变量地址对齐情况

标签: 测试null
617人阅读 评论(0) 收藏 举报
分类:

试代码:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>


using namespace std;


static void DelaySeconds(int Time);


int _tmain(int argc, _TCHAR* argv[])
{
char       CharPointer[13]     = {NULL};
char       CharPointer1[13]    = {NULL};
char       CharPointer2[13]    = {NULL};
short int  ShortIntPointer[13] = {NULL};
int        IntPointer[13]      = {NULL};
long  int  LongIntPointer[13]  = {NULL};


cout<<"CharPointer    :"<<&CharPointer<<endl;
cout<<"CharPointer + 1:"<<CharPointer+1<<endl;
cout<<"CharPointer1   :"<<&CharPointer1<<endl;
cout<<"CharPointer2   :"<<&CharPointer2<<endl;


cout<<"ShortIntPointer    :"<<&ShortIntPointer<<endl;
cout<<"ShortIntPointer + 1:"<<ShortIntPointer+1<<endl;


cout<<"IntPointer        :"<<&IntPointer<<endl;
cout<<"IntPointer + 1    :"<<IntPointer+1<<endl;


cout<<"LongIntPointer     :"<<&LongIntPointer<<endl;
cout<<"LongIntPointer + 1 :"<<LongIntPointer+1<<endl;

DelaySeconds(60);


return 0;
}


void DelaySeconds(int Time)
{
    Sleep(Time*1000);
}

打印结果:



结果分析:从打印结果分析得出所有数组的首地址都是四字节对齐

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:340390次
    • 积分:5220
    • 等级:
    • 排名:第5238名
    • 原创:165篇
    • 转载:88篇
    • 译文:5篇
    • 评论:47条
    最新评论