数据有常量和变量组成。
在程序运行过程中,常量的值不能变,变量的值可以变。
r表示回车:
#include
using namespace std;
int main()
{
cout << "zhershinyindaonqianndaonti";
}
#include
using namespace std;
int main()
{
cout << "zher";
}
\表示字符'',"表示双引号,'表示单引号。ASCII字符常量占用1字节。
#include
using namespace std;
int main()
{
cout << "zhe\";
}
三种声明形式,例:
1:
#include
using namespace std;
int main()
{
const int A=5;
cout << A;
}
2:
#include
using namespace std;
int main()
{
int const A = 5;
cout << A;
}
3:
#include
using namespace std;
#define A 5
int main()
{
cout << A;
}
or like
#include
using namespace std;
#define A 5
int main()
{
int c = 5, Y;
Y = c * A;
cout << Y;
}
在手打该project代码中遇到的问题:
#include
using namespace std;
#define A=5 //这里输入=错了,不符合格式
int main()
{
cout << A;
}
书P21例2-2:
#include
using namespace std;
void main()
{
int num, total;
const int PRICE = 30; num = 10;
total = num * PRICE;
cout << "total=" << total << endl;
}
#include
using namespace std;
#define PRICE 30
void main()
{
int num,total;num=10;
total=num* PRICE;
cout<<"total="< } 要注意的是,符号常量与变量不同,它的值在其作用域内不能改变,也不能再被赋值。 使用符号常量的好处是含义清楚,且能做到“一改全改”。



