-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add typedef file && show diff in struct
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |