欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++的對象特性和友元你真的了解嗎

 更新時間:2022年02月08日 16:06:36   作者:超級小何  
這篇文章主要為大家詳細(xì)介紹了C++的對象特性和友元,使用數(shù)據(jù)庫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

對象特征

構(gòu)造函數(shù)和析構(gòu)函數(shù)

對象的初始化和清理也是兩個非常重要的安全問題

一個對象或者變量沒有初始狀態(tài),對其使用后果也是未知

同樣的使用完一個對象或變量,沒有及時清理,也會造成一定的安全問題 

  • 構(gòu)造函數(shù):主要作用在于創(chuàng)建對象時為對象的成員屬性賦值,構(gòu)造函數(shù)由編譯器自動調(diào)用,無須手動調(diào)用
  • 析構(gòu)函數(shù):主要作用在于對象銷毀前系統(tǒng)自動調(diào)用,執(zhí)行一些清理工作

構(gòu)造函數(shù)語法:類名(){}

1.構(gòu)造函數(shù),沒有返回值也不寫void

2.函數(shù)名稱與類名相同

3.構(gòu)造函數(shù)可以有參數(shù),因此可以發(fā)生重載

4.程序在調(diào)用對象時候會自動調(diào)用構(gòu)造,無須手動調(diào)用,而且只會調(diào)用一次 

析構(gòu)函數(shù)語法:~類名(){}

1.析構(gòu)函數(shù),沒有返回值也不寫void

2.函數(shù)名稱與類名相同,在名稱前加上符號~

3.析構(gòu)函數(shù)不可以有參數(shù),因此不可以發(fā)生重載

4.程序在調(diào)用對象前會自動調(diào)用析構(gòu),無須手動調(diào)用,而且只會調(diào)用一次 

#include<iostream>
using namespace std;
//對象的初始化和清理
//1.構(gòu)造函數(shù)  實現(xiàn)初始化的操作
class Person {
public:
	//1構(gòu)造函數(shù)
	//沒有返回值  不用寫void
	//函數(shù)名 與類名相同
	//構(gòu)造函數(shù)可以有參數(shù),可以發(fā)生重載
	//創(chuàng)建對象時,構(gòu)造函數(shù)會自動調(diào)用,而且只調(diào)用一次
	Person() {
		cout<< "Person構(gòu)造函數(shù)的調(diào)用" << endl;
	}
	//2.析構(gòu)函數(shù)  實現(xiàn)清理的操作
	//沒有返回值 不寫void 
	//函數(shù)名和類名相同 在名稱前加一個~
	//析構(gòu)函數(shù)不可以有參數(shù),不可以發(fā)生重載
	//對象在銷毀前 會自動調(diào)用析構(gòu)函數(shù) 而且只會調(diào)用一次
	~Person() {
		cout << "Person析構(gòu)函數(shù)的調(diào)用" << endl;
	}
};
//構(gòu)造和析構(gòu)都是必須有的實現(xiàn),如果我們自己不提供,編譯器會提供一個空實現(xiàn)的構(gòu)造和析構(gòu)
void test01() {
	Person p;//在棧上的數(shù)據(jù),test01執(zhí)行完畢后,釋放這個對象
}
 int main() {
	test01();
	system("pause");
	return 0;
}

函數(shù)的分類以及調(diào)用

構(gòu)造函數(shù)的分類以及調(diào)用

兩種分類方式:

  • 按參數(shù)分為:有參構(gòu)造和無參構(gòu)造
  • 按類型分:普通構(gòu)造和拷貝構(gòu)造

三種調(diào)用方式:

  • 括號法
  • 顯示法
  • 隱式轉(zhuǎn)換法
#include<iostream>
using namespace std;
//構(gòu)造函數(shù)的分類及調(diào)用
//分類
//按照參數(shù)分類  無參構(gòu)造(默認(rèn)構(gòu)造)和有參構(gòu)造
//按照類型分類  普通構(gòu)造 拷貝構(gòu)造
class Person {
public:
	//構(gòu)造函數(shù)
	Person() {
 		cout << "Person的無參構(gòu)造函數(shù)調(diào)用" << endl;
	}
	Person(int a) {
		age = a;
		cout << "Person的有參構(gòu)造函數(shù)調(diào)用" << endl;
	}
	//拷貝構(gòu)造函數(shù)
	Person(const Person &p) {
		//將傳入的人身上的所有屬性,拷貝到“我”身上
		age = p.age;
		cout << "Person的拷貝構(gòu)造函數(shù)調(diào)用" << endl;
	}
	~Person() {
		cout << "Person的析構(gòu)函數(shù)調(diào)用" << endl;
	}
	int age;
};
//調(diào)用
void test01() {
	//1.括號法
	//Person p1;//默認(rèn)函數(shù)調(diào)用
	//Person p2(10);//有參構(gòu)造函數(shù)
	//Person p3(p2);//拷貝構(gòu)造函數(shù)
	//注意事項
	//調(diào)用默認(rèn)構(gòu)造函數(shù)的時候,不要加()
	//因為下面這行代碼,編譯器會認(rèn)為是一個函數(shù)的聲明,不會認(rèn)為在創(chuàng)建對象
	//Person p1();
  	/*cout << "p2的年齡:" << p2.age << endl;
	cout << "p3的年齡:" << p3.age << endl;*/
	//2.顯示法
	//Person p1;
	//Person p2 = Person(10);//有參構(gòu)造
	//Person p3 = Person(p3);//拷貝構(gòu)造
	//Person(10);//匿名對象 特點:當(dāng)前行執(zhí)行結(jié)束后,系統(tǒng)會立即回收掉匿名對象
	//
	// 注意事項2
	// 不要利用拷貝構(gòu)造函數(shù),初始化匿名對象  編譯器會認(rèn)為Person(p3) === Person p3;對象聲明
	//Person(p3);
 	//3.隱式轉(zhuǎn)換法
	Person p4 = 10;//相當(dāng)于 寫了 Person p4 = Person(10); 有參構(gòu)造
	Person p5 = p4;//拷貝構(gòu)造
}
int main() {
	test01();
	system("pause");
	return 0;
}

拷貝構(gòu)造函數(shù)調(diào)用時機(jī)

拷貝構(gòu)造函數(shù)調(diào)用時機(jī)通常有三種情況

1.使用一個已經(jīng)創(chuàng)建完畢的對象來初始化一個新對象

2.值傳遞的方式給函數(shù)參數(shù)傳值

3.以值方式返回局部對象

#include<iostream>
using namespace std;
//拷貝構(gòu)造函數(shù)的調(diào)用時機(jī)
//1.使用一個已經(jīng)創(chuàng)建完畢的對象來初始化一個新對象
//2.值傳遞的方式給函數(shù)參數(shù)傳值
//3.值方式返回局部對象
class Person {
public:
	Person() {
		cout << "Person的默認(rèn)構(gòu)造函數(shù)調(diào)用" << endl;
	}
	Person(int age) {
		cout << "Person的有參構(gòu)造函數(shù)調(diào)用" << endl;
		m_Age = age;
	}
	Person(const Person &p) {
		cout << "Person的拷貝構(gòu)造函數(shù)調(diào)用" << endl;
		m_Age = p.m_Age;
	}
	~Person() {
 		cout << "Person析構(gòu)函數(shù)調(diào)用" << endl;
	}
	int m_Age;
};
//拷貝構(gòu)造函數(shù)的調(diào)用時機(jī)
//1.使用一個已經(jīng)創(chuàng)建完畢的對象來初始化一個新對象
void test01() {
	Person p1(20);
	Person p2(p1);
	cout << "p2的年齡為:" << p2.m_Age << endl;
}
//2.值傳遞的方式給函數(shù)參數(shù)傳值
void doWork(Person p) {
  }
 void test02() {
	Person p;
	doWork(p);
}
 //3.值方式返回局部對象
Person doWork2() {
	Person p1;
	return p1;
}
void test03() {
	Person p = doWork2();
}
int main() {	
	//test01();
	//test02();
	test03();
	system("pause");
	return 0;
}

 構(gòu)造函數(shù)調(diào)用規(guī)則

默認(rèn)情況下,c++編譯器至少給一個類添加3個函數(shù)

1.默認(rèn)構(gòu)造函數(shù)(無參,函數(shù)體為空)

2.默認(rèn)析構(gòu)函數(shù)(無參,函數(shù)體為空)

3.默認(rèn)拷貝構(gòu)造函數(shù),對屬性進(jìn)行值拷貝

構(gòu)造函數(shù)調(diào)用規(guī)則如下

如果用戶定義有參構(gòu)造函數(shù),c++不再提供默認(rèn)無參構(gòu)造,但是會提供默認(rèn)拷貝構(gòu)造

如果用戶定義拷貝構(gòu)造函數(shù),c++不再提供其他構(gòu)造函數(shù) 

#include<iostream>
using namespace std;
//構(gòu)造函數(shù)的調(diào)用規(guī)則
//1.創(chuàng)建了一個類,c++編譯器會給每個類都添加至少三個函數(shù)
//默認(rèn)構(gòu)造  (空實現(xiàn))
//析構(gòu)函數(shù)  (空實現(xiàn))
//拷貝構(gòu)造  (值拷貝)
//2.如果我們寫了有參構(gòu)造函數(shù),編譯器就不再提供默認(rèn)構(gòu)造,依然提供拷貝構(gòu)造
//如果我們寫了拷貝構(gòu)造函數(shù),編譯器不再提供其他構(gòu)造函數(shù)了
class Person {
public:
	/*Person() {
		cout << "Person的默認(rèn)構(gòu)造函數(shù)調(diào)用" << endl;
	}*/
	/*Person(int age) {
		cout << "Person的有參構(gòu)造函數(shù)調(diào)用" << endl;
		m_Age = age;
	}*/
	Person(const Person& p) {
		cout << "Person的拷貝構(gòu)造函數(shù)調(diào)用" << endl;
		m_Age = p.m_Age;
}
 	~Person() {
		cout << "Person的析構(gòu)函數(shù)調(diào)用" << endl;
	}
	int m_Age;
};
//void test01() {
//	Person p;
//	p.m_Age = 18;
//	Person p2(p);
//	cout << "p2的年齡為:" << p2.m_Age << endl;
//}
void test02() {
	Person p(28);
	Person p2(p);
	cout << "p2的年齡為:" << p2.m_Age << endl;
}
int main() {
	//test01();
	test02();
	system("pause");
	return 0;
}

深拷貝與淺拷貝

  • 淺拷貝:簡單的賦值拷貝操作
  • 深拷貝:在堆區(qū)重新申請空間,進(jìn)行拷貝操作
#include<iostream>
using namespace std;
//深拷貝與淺拷貝
class Person {
public:
	Person() {
		cout << "Person的默認(rèn)構(gòu)造函數(shù)調(diào)用" << endl;
	}
	Person(int age,int height) {
		m_Age = age;
		m_Height = new int(height);
		cout << "Person的有參構(gòu)造函數(shù)調(diào)用" << endl;
	}
	Person(const Person &p) {
		cout << "Person 拷貝構(gòu)造函數(shù)的調(diào)用" << endl;
		m_Age = p.m_Age;
		//m_Height = p.m_Height; 編譯器默認(rèn)實現(xiàn)就是這行代碼
		//深拷貝操作
		//如果不利于深拷貝在堆區(qū)創(chuàng)建內(nèi)存,會導(dǎo)致淺拷貝帶來的重復(fù)釋放堆區(qū)問題
		m_Height = new int(*p.m_Height);
	}
	~Person() {
		//析構(gòu)堆區(qū),將堆區(qū)開辟數(shù)據(jù)做釋放操作
		if (m_Height != NULL) {
			delete m_Height;
			m_Height = NULL;
			//淺拷貝帶來的問題就是堆區(qū)的問題重復(fù)釋放
			//淺拷貝的問題 要利用深拷貝進(jìn)行解決
		}
		cout << "Person的析構(gòu)函數(shù)調(diào)用" << endl;
	}
	int m_Age;//年齡
	int* m_Height;//身高
};
void test01() {
	Person p1(18,160);
	cout << "p1的年齡為:" << p1.m_Age <<"身高為:"<<*p1.m_Height << endl;
	Person p2(p1);
	cout << "p2的年齡為:" << p2.m_Age <<"身高為:"<<*p2.m_Height << endl;
}
int main() {
	test01();
	system("pause");
	return 0;
}

如果屬性有在堆區(qū)開辟的,一定要自己提供拷貝構(gòu)造函數(shù),防止淺拷貝帶來的問題 

初始化列表

作用:c++提供了初始化列表語法,用來初始化屬性

語法:構(gòu)造函數(shù)():屬性1(值1),屬性2(值2)...{}

#include<iostream>
using namespace std;
//初始化列表
class Person {
public:
	//傳統(tǒng)初始化操作
	/*Person(int a, int b, int c) {
		m_A = a;
		m_B = b;
		m_C = c;
	}*/
	//初始化列表初始化屬性
	Person(int a,int b,int c) :m_A(a), m_B(b), m_C(c) {
 	}
	int m_A;
	int m_B;
	int m_C;
};
void test01() {
	//Person p(10, 20, 30);
	Person p(30,20,10);
	cout << "m_A = " << p.m_A << endl;
	cout << "m_B = " << p.m_B << endl;
	cout << "m_C = " << p.m_C << endl;
  }
int main() {
	test01();
	system("pause");
	return 0;
}

類對象作為類變量

c++類中的成員可以是另一個類的對象,我們稱該成員為 對象成員

例如:

class A{}

class B

{

         A a;

}

B類中有對象A作為成員去,A為對象成員

#include<iostream>
using namespace std;
//類對象作為類成員
//手機(jī)類
class Phone {
public:
	Phone(string pName) {
		cout << "Phone的構(gòu)造函數(shù)調(diào)用" << endl;
		m_PName = pName;
	}
	~Phone() {
		cout << "Phone的析構(gòu)函數(shù)調(diào)用" << endl;
	}
	//手機(jī)品牌名稱
	string m_PName;
 };
//人類
class Person {
public:
	//Phone m_Phone = pName  隱式轉(zhuǎn)換法
	Person(string name, string pName):m_Name(name),m_Phone(pName)
	{
		cout << "Person的構(gòu)造函數(shù)調(diào)用" << endl;
	}
	~Person() {
		cout << "Person的析構(gòu)函數(shù)調(diào)用" << endl;
	}
	//姓名
	string m_Name;
	//手機(jī)
	Phone m_Phone;
};
//當(dāng)其他類對象作為本類成員,構(gòu)造時先構(gòu)造類對象,再構(gòu)造自身,析構(gòu)的順序與構(gòu)造相反
void test01() {
	Person p("張三","蘋果");
	cout << p.m_Name << "拿著" << p.m_Phone.m_PName << endl;
 }
int main() {
	test01();
	system("pause");
	return 0;
}

靜態(tài)成員

靜態(tài)成員就是在成員變量和成員函數(shù)前加上關(guān)鍵字static,稱為靜態(tài)成員

靜態(tài)成員分為:

靜態(tài)成員變量

所有對象共享一份數(shù)據(jù)

在編譯階段分配內(nèi)存

類內(nèi)聲明,類外初始化

靜態(tài)成員函數(shù)

所有對象共享同一個函數(shù)

靜態(tài)成員函數(shù)只能訪問靜態(tài)成員變量 

#include<iostream>
using namespace std;
//靜態(tài)成員函數(shù)
//所有對象共享同一個函數(shù)
//靜態(tài)成員函數(shù)只能訪問靜態(tài)成員變量
class Person {
public:
	//靜態(tài)成員函數(shù)
	static void func() {
		m_A = 100;//靜態(tài)成員函數(shù)可以訪問靜態(tài)成員變量
		//m_B = 200;//靜態(tài)成員函數(shù)不可以訪問非靜態(tài)成員變量,無法區(qū)分到底是哪個m_B
		cout << "static void func的調(diào)用" << endl;
	}
	static int m_A;//靜態(tài)成員變量
	int m_B;//非靜態(tài)成員變量
	//靜態(tài)成員函數(shù)也是有訪問權(quán)限的
private:
	static void func2() {
		cout << "static void func2的調(diào)用" << endl;
	}
};
int Person::m_A = 0;
//有兩種訪問方式
void test01() {
	//1.通過對象進(jìn)行訪問
	Person p;
	p.func();
	//2.通過類名訪問
	Person::func();
	//Person::func2();類外訪問不到私有的靜態(tài)成員函數(shù)
}
int main() {
	test01();
	system("pause");
	return 0;
}

成員變量和成員函數(shù)分開儲存

在c++中,類的成員變量和成員函數(shù)分開存儲

只有非靜態(tài)成員變量才屬于類的對象上

#include<iostream>
using namespace std;
//成員變量和成員函數(shù)是分開存儲的
class Person {
	int m_A;//非靜態(tài)成員變量  屬于類的對象上的
	static int m_B;//靜態(tài)成員變量  不屬于類的對象上
	void func() {}//非靜態(tài)成員函數(shù)  不屬于類的對象上
	static void func2() {}//靜態(tài)成員函數(shù)  不屬于類的對象上
};
int Person::m_B = 0;
void test01() {
	Person p;
	//空對象占用的內(nèi)存空間為:1
	//c++編譯器會給每個空對象也分配一個字節(jié)空間,是為了區(qū)分空對象占內(nèi)存的位置
	//每個空對象也應(yīng)該有一個獨一無二的內(nèi)存地址
	cout << "size of p = "<<sizeof(p) << endl;
}
void test02() {
	Person p;
	cout << "size of p = " << sizeof(p) << endl;
}
int main() {
	//test01();
	test02();
	system("pause");
	return 0;
}

this指針的用途

  • this指針指向被調(diào)用的成員函數(shù)所屬的對象
  • this指針是隱含每一個非靜態(tài)成員函數(shù)內(nèi)的一種指針
  • this指針不需要定義,直接使用即可

this指針的用途:

當(dāng)形參和成員變量同名時,可用this指針來區(qū)分

在類的非靜態(tài)成員函數(shù)中返回對象本身,可使用return * this返回 

#include<iostream>
using namespace std;
class Person {
public:
	Person(int age) {
		//this指針指向被調(diào)用的成員函數(shù)所屬的對象
		this->age = age;
	}
	int age;
	Person PersonAddAge(Person &p) {
		this->age += p.age;
		//this指向p2的指針,而*this指向的就是p2這個對象本體
		return *this;
	}
};
 //1.解決名稱沖突
void test01() {
	Person p1(18);
	cout << "p1的年齡為:" << p1.age << endl;
}
//2.返回對象本身用*this
void test02() {
	Person p1(10);
	Person p2(10);
	//鏈?zhǔn)骄幊趟枷?
	p2.PersonAddAge(p1).PersonAddAge(p1).PersonAddAge(p1);
	cout << "p2的年齡為:" << p2.age << endl;
}
 int main() {
	//test01();
	test02();
	system("pause");
	return 0;
}

空指針訪問成員

c++中空指針也是可以調(diào)用成員函數(shù)的,但是也要注意有沒有用到this指針

如果用到this指針,需要加以判斷保證代碼的健壯性

#include<iostream>
using namespace std;
//空指針調(diào)用成員函數(shù)
class Person {
public:
 	void showClassName() {
		cout << "this is Person class" << endl;
	}
	void showPersonAge() {
		//報錯原因是因為傳入的指針是為NULL
		if (this == NULL)
		{
			return;
		}
		cout << "age = " <<this-> m_Age << endl;
	}
	int m_Age;
};
void test01() {
	Person* p = NULL;
	//p->showClassName();
	p->showPersonAge();
}
int main() {
	test01();
 	system("pause");
	return 0;
}

const修飾成員函數(shù)

常函數(shù)

成員函數(shù)后加const后我們稱這個函數(shù)為常函數(shù)

函數(shù)內(nèi)不可以修改成員屬性

成員屬性聲明時加關(guān)鍵字mutable后,在常函數(shù)中依然可以修改

常對象:

聲明對象前加const稱該對象為常對象

常對象只能調(diào)用常函數(shù) 

#include<iostream>
using namespace std;
//空指針調(diào)用成員函數(shù)
class Person {
public:
 	void showClassName() {
		cout << "this is Person class" << endl;
	}
	void showPersonAge() {
		//報錯原因是因為傳入的指針是為NULL
		if (this == NULL)
		{
			return;
		}
		cout << "age = " <<this-> m_Age << endl;
	}
	int m_Age;
};
void test01() {
	Person* p = NULL;
	//p->showClassName();
	p->showPersonAge();
}
int main() {
	test01();
 	system("pause");
	return 0;
}

友元

友元的目的就是讓一個函數(shù)或者類訪問另一個類中私有成員 

友元關(guān)鍵字為friend  

友元的三種實現(xiàn):

  • 全局函數(shù)做友元
  • 類做友元
  • 成員函數(shù)做友元

全局函數(shù)做友元

#include<iostream>
using namespace std;
#include<string>
//建筑物類
class Building {
	//goodGay全局函數(shù)是Building好朋友,可以訪問Building中私有成員
	friend void goodGay(Building* building);
public:
	Building() {
		m_SittingRoom = "客廳";
		m_BedRoom = "臥室";
	}
public:
	string m_SittingRoom;//客廳
private:
	string m_BedRoom;//臥室
};
//全局函數(shù)
void goodGay(Building *building) {
	cout << "好基友全局函數(shù) 正在訪問:" << building->m_SittingRoom << endl;
	cout << "好基友全局函數(shù) 正在訪問:"<<building->m_BedRoom << endl;
}
void test01() {
	Building building;
	goodGay(&building);
}
int main() {
	test01();
	system("pause");
	return 0;
}

類做友元

#include<iostream>
using namespace std;
#include<string>
//類做友元
class Building;
class GoodGay {
public:
	GoodGay();
	void visit();//參觀函數(shù) 訪問Building中的屬性
	Building* building;
};
class Building {
	//GoodGay類是本來的好朋友,可以訪問本類中私有成員
	friend class GoodGay;
public:
	Building();
public:
	string m_SittiingRoom;//客廳
private:
	string m_BedRoom;//臥室
};
//類外寫成員函數(shù)
Building::Building() {
	m_SittiingRoom = "客廳";
	m_BedRoom = "臥室";
}
GoodGay::GoodGay() {
	//創(chuàng)建建筑物對象
	building = new Building;
}
void GoodGay::visit() {
	cout << "好基友類正在訪問:"<<building->m_SittiingRoom << endl;
	cout << "好基友類正在訪問:" << building->m_BedRoom << endl;
}
void test01() {
	GoodGay gg;
	gg.visit();
}
int main() {
	test01();
	system("pause");
	return 0;
}

成員函數(shù)做友元

#include<iostream>
using namespace std;
#include<string>
class Building;
class GoodGay {
public:
	GoodGay();
	void visit();//讓visit函數(shù)可以訪問Building中的私有成員
	void visit2();//讓visit函數(shù)不可以訪問Building中的私有成員
	Building* building;
};
class Building {
	//告訴編譯器 GoodGay類下的visit成員函數(shù)作為本類的好朋友,可以訪問私有成員
	friend void GoodGay:: visit();
public:
	Building();
public:
	string m_SittingRoom;//客廳
private:
	string m_BedRoom;//臥室
 };
//類外實現(xiàn)成員函數(shù)
Building::Building() {
	m_SittingRoom = "客廳";
	m_BedRoom = "臥室";
}
GoodGay::GoodGay() {
	building = new Building;
}
void GoodGay::visit() {
	cout << "visit函數(shù)正在訪問"<<building->m_SittingRoom << endl;
	cout << "visit函數(shù)正在訪問" << building->m_BedRoom << endl;
}
void GoodGay::visit2() {
	cout << "visit2函數(shù)正在訪問" << building->m_SittingRoom << endl;
	//cout << "visit2函數(shù)正在訪問" << building->m_BedRoom << endl;
}
void test01() {
	GoodGay gg;
	gg.visit();
	gg.visit2();
}
int main() {
	test01();
 	system("pause");
	return 0;
}

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!       

相關(guān)文章

  • C++標(biāo)準(zhǔn)庫封裝的vector數(shù)組

    C++標(biāo)準(zhǔn)庫封裝的vector數(shù)組

    這篇文章主要介紹了C++標(biāo)準(zhǔn)庫封裝的vector數(shù)組,vector創(chuàng)建的對象包含眾多封裝好的函數(shù),想了解其相關(guān)資料的小伙伴可以參考下面文章內(nèi)容,希望對你的學(xué)習(xí)有所幫助
    2022-03-03
  • 用C語言實現(xiàn)猜數(shù)字

    用C語言實現(xiàn)猜數(shù)字

    這篇文章主要為大家詳細(xì)介紹了用C語言實現(xiàn)猜數(shù)字,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • C語言預(yù)處理詳解

    C語言預(yù)處理詳解

    這篇文章主要給大家介紹了關(guān)于C語言之預(yù)處理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-10-10
  • C++面試題之?dāng)?shù)a、b的值互換(不使用中間變量)

    C++面試題之?dāng)?shù)a、b的值互換(不使用中間變量)

    這篇文章主要介紹了不使用中間變量,C++實現(xiàn)數(shù)a、b的值互相轉(zhuǎn)換操作,感興趣的小伙伴們可以參考一下
    2016-07-07
  • C語言詳細(xì)講解if語句與switch語句的用法

    C語言詳細(xì)講解if語句與switch語句的用法

    用 if 語句可以構(gòu)成分支結(jié)構(gòu),它根據(jù)給的條件進(jìn)行判定,以決定執(zhí)行哪個分支程序段,C 語言中還有另外一種分支語句,就是 switch 語句
    2022-05-05
  • c病毒程序原理分析(防范病毒 c語言小病毒示例)

    c病毒程序原理分析(防范病毒 c語言小病毒示例)

    這篇文章主要介紹了病毒程序原理,寫個小程序做演示,大家可以參考這個以防中相似C病毒
    2013-12-12
  • c++中const的使用詳解

    c++中const的使用詳解

    本篇文章是對c++中的const的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • 一文詳解C++關(guān)鍵字nullptr及與NULL的區(qū)別

    一文詳解C++關(guān)鍵字nullptr及與NULL的區(qū)別

    這篇文章主要給大家詳細(xì)介紹了C++關(guān)鍵字nullptr,及?NULL與nullptr的區(qū)別,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • 淺談C語言的字符串分割

    淺談C語言的字符串分割

    下面小編就為大家?guī)硪黄獪\談C語言的字符串分割。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05
  • 使用C++實現(xiàn)全排列算法的方法詳解

    使用C++實現(xiàn)全排列算法的方法詳解

    本篇文章是對使用C++實現(xiàn)全排列算法的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05

最新評論