關於一些在c與c++中的特殊關鍵字的詳解與用法

2020-08-12 23:41:13

關於一些在c與c++中的特殊關鍵字的詳解與用法,這些都是個人目前見過並記得的,不能說很全面,希望後面有機會再補全

1、sizeof:計算某個型別或者一些變數所佔的位元組數

用法:

	printf("%d\n",sizeof(int));
	//計算int型別所佔的位元組數,結果爲:4
	
	int num[] = {1,2,3};	
	printf("%d\n",sizeof(num));
	//計算num陣列所佔的位元組數,結果爲:4*3 = 12
2、LINE:常用於偵錯程式碼,找出錯的位置

用法:

			printf("%d\n",__LINE__);
			//列印當前行數
3、func:指當前所在的函數,用於偵錯

用法:

			printf("%s\n",__func__);
			//列印當前所在函數
4、BUFSIZ:系統緩衝區的大小(注:系統緩衝區與檔案緩衝區不是同一個)
	原名:Buffer size

	This macro constant expands to an integral expression with the size of the 
	buffer used by the setbuf function.

用法:

		printf("%d\n",BUFSIZ);
		//	64位元系統下結果爲:8192
5、EOF:到達檔案末尾或者遇到CTRL+c時將讓程式結束執行,指示其他一些故障情況
	原名:end of file		

	It is a macro definition of type int that expands into a negative integral constant expression (generally, -1).

	It is used as the value returned by several functions in header <cstdio> to indicate that the End-of-File has been reached or to signal some other failure conditions.

	It is also used as the value to represent an invalid character.		

用法:

			int num;
			while(scanf("%d",&num)!=EOF);
			//代表只要沒有按下CTRL+c就一直回圈
6、FOPEN_MAX:指使用fopen等檔案io函數開啓檔案時,可以開啓的檔案最大個數,所有系統的FOPEN_MAX應大於7。
	原名:Potential limit of simultaneous open streams
	
	This macro constant expands to an integral expression that represents the maximum number of files that can be opened simultaneously.

	Particular library implementations may count files opened by tmpfile towards this limit. Implementations may also allow more files to be opened beyond this limit.

	FOPEN_MAX shall be greater than 7 on all systems.

用法:

		printf("%d\n",FOPEN_MAX);
		//	64位元系統下結果爲:16
7、L_tmpnam:代表臨時檔案名字的最小長度
	原名:Minimum length for temporary file name

	This macro constant expands to an integral expression corresponding to 
	
	the size needed for an array of char elements to hold the longest file name 

	string possibly generated by tmpnam.

用法:

		printf("%d\n",L_tmpnam);
		//	64位元系統下結果爲:20
8、TMP_MAX:臨時檔案數,不能小於25。
	原名:Number of temporary files
	
	This macro expands to the minimum number of unique temporary file 
	
	names that are guaranteed to be possible to generate using tmpnam.

	This value cannot be lower than 25.

	Particular library implementations may count file names used by files created with tmpfile towards this limit.

用法:

		printf("%d\n",TMP_MAX);
		//	64位元系統下結果爲:238328
9、NULL:空指針,一般用於定義指針時先存NULL的地址,防止它指向記憶體一些其他地方
	原名:Null pointer		

	This macro expands to a null pointer constant.

	CC++98C++11:
	A null-pointer constant is an integral constant expression that evaluates to 
	zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0).

	A null pointer constant can be converted to any pointer type (or pointer-to-
	member type), which acquires a null pointer value. This is a special value 
	that indicates that the pointer is not pointing to any object.

用法:

		int *p = NULL;
		//把p指針初始化爲空指針
10、FILENAME_MAX:系統所支援的檔名最大長度
	原名:Maximum length of file names

	This macro constant expands to an integral expression corresponding to the size needed for an array of char elements
	 
	to hold the longest file name string allowed by the library. Or, if the library imposes no such restriction, 
	
	it is set to the recommended size for character arrays intended to hold a file name.

用法:

		printf("%d\n",FILENAME_MAX);
		//	64位元系統下結果爲:4096	
可能有一些未能總結到位的,或者有什麼錯誤,請多指點,非常感謝,希望能幫到有需要的人