日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C語言中const和define的區別你了解嘛_C 語言

作者:Sparky* ? 更新時間: 2022-05-16 編程語言

define和const使用

在這里插入圖片描述

在這里插入圖片描述

const和define區別

在這里插入圖片描述

#include 
#define A 1
#define B (A+3)   //
#define C A/B*3 //  
//const不能重定義,不可以定義兩個一樣的,而define通過undef取消某個符號的定義,再重新定義 
const double PI=3.14;
//const double PI=3.145;
#define PI2 3.14
#undef PI2 //  取消PI2 的定義
#define PI2 3.145
void main() {
	//
	//分析過程
	//#define 就是一個簡單的替換!!!
	//C 其實是  A/A+3*3 = 1/1 + 3 * 3 = 1 + 9 = 10
	//C 其實是  A/(A+3)*3 = 1/(1+3) * 3 = 1/4 *3 = ?
	double d1 = 1.0/4 *3 ; // 0.25 * 3  = 0.75
	printf("\nc=%.2f", C);// 問 c = ? 
	printf("\nd1=%.2f", d1);
	getchar();
}
#include 
//#define DEBUG
void main() {
#ifdef DEBUG //如果定義過 DEBUF
		printf("ok, 調試信息");
#endif
#ifndef DEBUG //如果沒有定義過 DEBUF
		printf("hello, 另外的信息");
#endif
//		printf("%d",n);
		getchar();
}

總結

原文鏈接:https://blog.csdn.net/weixin_43362002/article/details/123449350

欄目分類
最近更新