<C Primer Plus >1 Constants and the C Preprocessor

 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.

转载于:https://www.cnblogs.com/michael2016/p/6580050.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值