当前位置:网站首页>You Li takes you to talk about C language 7 (define constants and macros)

You Li takes you to talk about C language 7 (define constants and macros)

2022-07-05 04:24:00 Lu Youli

Print shaping

#define MAX 1000;

int main()
{
    
	int a = MAX;
	printf("%d\n", a);
	return 0;
}

Print string

#define TAL "hi,bro!"

int main()
{
    
	printf("%s\n", TAL);
	return 0;
}

#define Defining macro

Before, we used the method of function to get the larger value between two numbers , Let's review again

Function implementation

int get_max(int x, int y)
{
    
	int z = 0;
	z = (x > y ? x : y);
	return z;
}


int main()
{
    
	int a = 50;
	int b = 30;
	int m = get_max(a ,b);
	printf(" Larger value :%d\n", m);
	return 0;
}

#define Realization

// When defining a macro , Macro names are generally capitalized 
#define MAX(x, y) (x>y?x:y)

int main()
{
    
	int a = 50;
	int b = 30;
	int m = MAX(a, b);
	printf(" Larger value :%d\n", m);
	return 0;
}
原网站

版权声明
本文为[Lu Youli]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140642532118.html