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.
时间: 2024-11-12 15:34:40

Constants and the C Preprocessor的相关文章

Android gdb so

gdb debug an android application 1.gdb 要有gdbserver 一般模拟器默认装有gdbserver,如2.3.3的模拟器,看一下有没有: D:\Developer\sdk\platform-tools>adb shell ls -l /system/bin/gdb*-rwxr-xr-x root shell 5664 2010-07-01 05:03 gdbjithelpe-rwxr-xr-x root shell 151868 2010-05-11 09

Objective-C教程备忘单

终极版本的Objective-C教程备忘单帮助你进行iOS开发. 想开始创建你的第一个iOS应用程序么?那么看一下这篇很棒的教程吧:Create your first iOS 7 Hello World Application 注:这篇文章我写了三天,可能在一些必要的地方使用了编辑和说明,所以如果有任何疑问和修改建议请在下方评论. 这不是一个初学者指南,也不是关于Objective-C的详细讨论,这是关于常见的和高水平的论题的快速索引. 如果这里有些问题没有涉及到,你也可以查阅以下文章: Obj

Constants in C++

The first motivation for const seems to have been to eliminate the use of preprocessor #define for value substitution. It has since been put to use for pointers, function arguments, return types, class objects and member functions. (Page 334) 1 Value

Java中的Constants类

1.遇到代码中的问题 String userName = (String) request.getParameter("userName"); String passWord = (String) request.getParameter("passWord"); String inputKaptcha = (String) request.getParameter("kaptcha"); //下面这句代码是什么意思??? String sess

Cross Platform Note: STD C++ Preprocessor directives &amp; pre-defined macros

ref: http://www.cplusplus.com/doc/tutorial/preprocessor/ concolusion: directives: #define #undef #include #if #else #elif #endif #ifdef #ifndef #error ( #warning is NOT A STANDARD DIRECTIVE,  since not shown in the page above, but most compilers have

C++ preprocessor &quot;/lib/cpp&quot; fails sanity check See `config.log&#39; for more details

Ubuntu 12.04环境下编译xapian时报此错误,因为从来没有在此系统下跑过C++,所以用C++编译器的时候出现此问题 出现该情况是由于c++编译器的相关package没有安装,以root用户登陆,在终端上执行: # sudo get-apt install glibc-headers # sudo get-apt install gcc-c++ 也可以 #sudo apt-get install build-essential 通过第二种方法安装完毕后,编译通过 C++ preproc

【转】linux configure报错configure: error: C++ preprocessor “/lib/cpp” fails sanity 的解决办法

/lib/cpp fails sanity check的解决 在某些软件的时候,运行./configure 会报错,错误提示为: configure: error: C++ preprocessor “/lib/cpp” fails sanity  check See `config.log’ for more details 解决办法:出现该情况是由于c++编译器的相关package没有安装,以root用户登陆,在终端上执行: # yum install glibc-headers # yum

Variable hoisting Global variables Constants

Another unusual thing about variables in JavaScript is that you can refer to a variable declared later, without getting an exception. This concept is known as hoisting; variables in JavaScript are in a sense "hoisted" or lifted to the top of the

[C++] 用Xcode来写C++程序[3] Constants

用Xcode来写C++程序[3] Constants 以下是一些基本数据的含义: 75 // int 75u // unsigned int 75l // long 75ul // unsigned long 75lu // unsigned long 3.14159 // 3.14159 6.02e23 // 6.02 x 10^23 1.6e-19 // 1.6 x 10^-19 3.0 // 3.0 3.14159L // long double 6.02e23f // float 'z'