欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++中typedef 及其與struct的結(jié)合使用

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

復(fù)制代碼 代碼如下:

//相當(dāng)于為現(xiàn)有類型創(chuàng)建一個(gè)別名,或稱類型別名。
//整形等
typedef int size;


//字符數(shù)組
char line[81];
char text[81];//=>

typedef char Line[81];
Line text, secondline;


//指針
typedef char * pstr;
int mystrcmp(pstr p1, pstr p2);//注:不能寫成int mystrcmp(const pstr p1, const pstr p3);因const pstr p1解釋為char * const cp(不是簡(jiǎn)單的替代)


//與結(jié)構(gòu)類型組合使用
typedef struct tagMyStruct
{
int iNum;
long lLength;
} MyStruct;//(此處MyStruct為結(jié)構(gòu)類型別名)=>

struct tagMyStruct
{
int iNum;
long lLength;
};//+
typedef struct tagMyStruct MyStruct;


//結(jié)構(gòu)中包含指向自己的指針用法
typedef struct tagNode
{
char *pItem;
pNode pNext;
} *pNode;//=>error
//1)
typedef struct tagNode
{
char *pItem;
struct tagNode *pNext;
} *pNode;
//2)
typedef struct tagNode *pNode;
struct tagNode
{
char *pItem;
pNode pNext;
};
//3)規(guī)范
struct tagNode
{
char *pItem;
struct tagNode *pNext;
};
typedef struct tagNode *pNode;


//與define的區(qū)別
//1)
typedef char* pStr1;//重新創(chuàng)建名字
#define pStr2 char *//簡(jiǎn)單文本替換
pStr1 s1, s2;
pStr2 s3, s4;=>pStr2 s3, *s4;
//2)define定義時(shí)若定義中有表達(dá)式,加括號(hào);typedef則無需。
#define f(x) x*x=>#define f(x) ((x)*(x))
main( )
{
int a=6,b=2,c;
c=f(a) / f(b);
printf("%d \\n",c);
}
//3)typedef不是簡(jiǎn)單的文本替換
typedef char * pStr;
char string[4] = "abc";
const char *p1 = string;
const pStr p2 = string;=>error
p1++;
p2++;

//1) #define宏定義有一個(gè)特別的長(zhǎng)處:可以使用 #ifdef ,#ifndef等來進(jìn)行邏輯判斷,還可以使用#undef來取消定義。
//2) typedef也有一個(gè)特別的長(zhǎng)處:它符合范圍規(guī)則,使用typedef定義的變量類型其作用范圍限制在所定義的函數(shù)或者文件內(nèi)(取決于此變量定義的位置),而宏定義則沒有這種特性。

復(fù)制代碼 代碼如下:

//
//C中定義結(jié)構(gòu)類型
typedef struct Student
{
int a;
}Stu;//申明變量Stu stu1;或struct Student stu1;
//或
typedef struct
{
int a;
}Stu;//申明變量Stu stu1;

//C++中定義結(jié)構(gòu)類型
struct Student
{
int a;
};//申明變量Student stu2;


//C++中使用區(qū)別
struct Student
{
int a;
}stu1;//stu1是一個(gè)變量 。訪問stu1.a

typedef struct Student2
{
int a;
}stu2;//stu2是一個(gè)結(jié)構(gòu)體類型 訪問stu2 s2; s2.a=10;
//還有待增加。

上一篇:c語言網(wǎng)絡(luò)編程-標(biāo)準(zhǔn)步驟(改進(jìn)版)

欄    目:C語言

下一篇:c語言文件讀寫示例(c語言文件操作)

本文標(biāo)題:C++中typedef 及其與struct的結(jié)合使用

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3785.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有