在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