您的位置:首页 > 编程语言 > C语言/C++

一段C++的程序,指针大小的,以及__LINE__,__FILE__两个宏

2008-02-29 15:22 375 查看
在C++中,宏__LINE__表示当前执行的行数

__FILE__表示当前的源文件的名字

#include <iostream>
#include <string>

using namespace std;

void main()
{
char p[10];

cout<<"The Length of p[10] is"<<sizeof(p)<<endl;

char* p1=NULL ;
void* p2=NULL;
int p3=0;

cout<<"The sizeof char* p1 is"<<sizeof(p1)<<endl;
cout<<"The sizeof void* p2 is"<<sizeof(p2)<<endl;
cout<<"The sizeof int p3 is"<<sizeof(p3)<<endl;

int line=__LINE__;
char *file = __FILE__;

cout<<"The filename is"<<(file)<<endl;
cout<<"The value of line is"<<line<<endl;
}

结果为:

TheLength of p[10] is 10

The sizeof char* p2 is 4

The sizeof void* p2 is 4

The sizeof int p3 is 4

The filename is E:/MSDev98/MyProjects/MyBasic/sizeof.cpp

The value of line is 20
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐