一段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
__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
相关文章推荐
- 通过一个c++程序来理解两个指针的赋值
- 【链表】C++快慢两个指针解决问题(分别求倒数第k个、中间以及环的入口结点)
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序
- c/C++编译的程序占用的内存以及More Effective C++ 条款1:指针与引用的区别
- java--封装一类Java对象,用户从输入对话框输入两个日期,程序将判断两个日期的大小关系(比如输出:您输入的第二个日期大于第一个日期)以及两个日期之间的间隔天数(比如输出:2006年6月6日和
- C++ 11 智能指针 lamda 以及一个 围棋程序
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)
- [C/C++]两个值得研究的程序(指针与内存分配)
- 简化以下程序,将两个 for 循环都替换为标准的 C++ 算法
- 对话框程序最大化 控件以及字体大小自适应
- C/C++程序——递归和循环实现阶乘,并比较N!与(2N N)的大小
- FILE指针在两个dll中无法正确操作的问题
- c/c++程序main函数参数解析,以及参数传递的不同方法
- c/c++ sizeof运算符详解以及对象大小
- C++ 06 继承与组合 (has-a is-a) 以及类大小的计算 虚基类对内存模型的影响(不考虑虚函数)
- c/c++ sizeof运算符详解以及对象大小
- 改善C++ 程序的150个建议学习之建议34:用智能指针管理通过new创建的对象
- C/C++语言宏的冷知识,内置宏,__FILE__,__LINE__,##, 可变参的宏...和__VA_ARGS__