Skip to content

Commit

Permalink
add typedef file && show diff in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kugouming committed Sep 11, 2016
1 parent d325085 commit dcd9f01
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions C++/typedef.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*************************************************************************
> File Name: typedef.cpp
> Author:
> Mail:
> Created Time: 日 9/11 15:52:46 2016
************************************************************************/

#include <iostream>
using namespace std;

// 给结构体定义一个新名字
typedef struct world
{
int x;
} hello; // hello 一个结构体类型=struct world

// 定义一个结构体变量
// struct hello2
struct
{
int x;
int y;
} he; // he 是一个变量

int main()
{

// 但是hello则必须先 hello hel;
// 然后 hel.x = 13;
hello hel;
hel.x = 13;
cout << "struct of x is: " << hel.x << endl;

// 使用时可以直接访问he.y
he.y = 131;
cout << "struct of y is: " << he.y << endl;

cout << "\n-------------------< 上面的验证结束 >---------------------\n" << endl;

int x = 12;

// typedef 为一个已有的类型取一个新的名字
typedef int hello;

hello y =15;

cout << "X value is: " << x << endl;
cout << "Y value is: " << y << endl;

return 0;
}

0 comments on commit dcd9f01

Please sign in to comment.