posts - 9,comments - 21,trackbacks - 0

#include <iostream>

typedef int prablint; //定义别名

int main()
{
    using namespace std;
    prablint a = 0;
    cout << sizeof(a) << endl;
    cout << sizeof(int) << endl;
   
    system("PAUSE");
    return 0;
}

posted on 2006-04-03 14:36 蕃豆仁 阅读(600) 评论(1)  编辑 收藏 引用 所属分类: C++ primer plus读书笔记

FeedBack:
#  typedef和#define
2006-04-03 14:47 | 蕃豆仁
#include <iostream>
//typedef和#define
typedef int prablint;
#define prablchar char

typedef int* prabl_int_p;
#define prabl_char_p char*


int main()
{
using namespace std;
prablint a = 0;
prablchar b = 'a';

prabl_int_p c,d;
prabl_char_p e,f;

cout << sizeof(a) << endl;
cout << sizeof(int) << endl;
cout << sizeof(b) << endl;
cout << sizeof(char) << endl;
cout << sizeof(c) << "," << sizeof(int*) << endl;
cout << sizeof(d) << "," << sizeof(int*) << endl;

cout << sizeof(e) << "," << sizeof(char*) << endl;
cout << sizeof(f) << "," << sizeof(char*) << endl; //f是char型,不是char*。所以用typedef是更安全的

system("PAUSE");
return 0;
}
  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理