码迷,mamicode.com
首页 > 其他好文 > 详细

Constants and the C Preprocessor

时间:2017-03-19 13:35:05      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:mem   tee   pre   error   make   read   value   har   3.1   

 1 #include <stdio.h>
 2 #define    PI 3.14159
 3 int main(void){
 4     float area, circum, radius;
 5 
 6     printf("What is the radius of your pizza>\n");
 7     scanf("%f", &radius);
 8     area = PI * radius *
 radius;
 9     circum = 2 * PI *radius;
10     printf("Your pizza parameters are as follows:\n");
11     printf("Circumference = %1.2f, area = %1.2f \n", circum, area);
12     getchar();
13     return 0;
14 }

The #define statement can be used for character and string constants,too . The following example are valid:

1 #define BEEP ‘\a‘
2 #define TEE ‘T‘
3 #define ESC ‘\033‘
4 #define OOPS "Now you have done it!"

Remember:
1 It is a sensible C tradition to type constants in uppercase.
2 Don‘t make the common error when using the #define.
3 The const Modifier makes variables read-only ;you cannot alter the value of the variables.
4 C has a third way to create symbolic constants,and that is the enum.

Constants and the C Preprocessor

标签:mem   tee   pre   error   make   read   value   har   3.1   

原文地址:http://www.cnblogs.com/michael2016/p/6580050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!