typedef struct 是什么意思
生活随笔
收集整理的這篇文章主要介紹了
typedef struct 是什么意思
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
typedef用于定義一種新類型
例如
定義了如下的結(jié)構(gòu)
typedef struct student
{
int age;
int score;
}STUDENT;
那么則有
STUDENT stu1;
就相當(dāng)于struct student stu1;
上面的結(jié)構(gòu)也可以直接定義為:
typedef struct
{
int age;
int score;
}STUDENT;
然后將STUDENT作為新類型使用,比如STUDENT stu1;
typedef聲明新的類型來代替已有的類型的名字。
如:
typedef int INTEGER;
下面兩行等價
int i;
INTEGER i;
可以聲明結(jié)構(gòu)體類型:
typedef struct
{
int age;
int score;
}STUDENT;
定義變量:
只能寫成 STUDENT stu;
如果寫成
typedef struct student
{
int age;
int score;
}STUDENT;
下面三行等價:
STUDENT stu;
struct student stu;
student stu;
1 #include <stdio.h> 2 #include <ctype.h> 3 #include <conio.h> 4 5 void main() 6 { 7 char letter; // Letter typed by the user 8 9 printf("Do you want to continue? (Y/N): "); 10 11 letter = getch(); // Get the letter 12 letter = toupper(letter); // Convert letter to uppercase 13 14 while ((letter != 'Y') && (letter != 'N')) 15 { 16 putch(3); // Beep the speaker 17 letter = getch(); // Get the letter 18 letter = toupper(letter); // Convert letter to uppercase 19 } 20 21 printf("\nYour response was %c\n", letter); 22 }
例如
定義了如下的結(jié)構(gòu)
typedef struct student
{
int age;
int score;
}STUDENT;
那么則有
STUDENT stu1;
就相當(dāng)于struct student stu1;
上面的結(jié)構(gòu)也可以直接定義為:
typedef struct
{
int age;
int score;
}STUDENT;
然后將STUDENT作為新類型使用,比如STUDENT stu1;
typedef聲明新的類型來代替已有的類型的名字。
如:
typedef int INTEGER;
下面兩行等價
int i;
INTEGER i;
可以聲明結(jié)構(gòu)體類型:
typedef struct
{
int age;
int score;
}STUDENT;
定義變量:
只能寫成 STUDENT stu;
如果寫成
typedef struct student
{
int age;
int score;
}STUDENT;
下面三行等價:
STUDENT stu;
struct student stu;
student stu;
1 #include <stdio.h> 2 #include <ctype.h> 3 #include <conio.h> 4 5 void main() 6 { 7 char letter; // Letter typed by the user 8 9 printf("Do you want to continue? (Y/N): "); 10 11 letter = getch(); // Get the letter 12 letter = toupper(letter); // Convert letter to uppercase 13 14 while ((letter != 'Y') && (letter != 'N')) 15 { 16 putch(3); // Beep the speaker 17 letter = getch(); // Get the letter 18 letter = toupper(letter); // Convert letter to uppercase 19 } 20 21 printf("\nYour response was %c\n", letter); 22 }
?
?轉(zhuǎn)載于:https://www.cnblogs.com/Zblogs/p/3361100.html
總結(jié)
以上是生活随笔為你收集整理的typedef struct 是什么意思的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WIN7下打开telnet工具
- 下一篇: 转载:CEO如何“养好CIO同时管好CI