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

本文介绍了使用Xcode进行C++编程的基础知识,包括基本数据类型如整型、浮点型、字符型等的表示方法,以及常量、布尔类型、指针的使用,并通过实例展示了如何使用宏定义来简化编程。

用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'        // 单个字符
"How do you do?"  // 字符串


一些符号的含义:


bool类型以及指针
bool foo = true;
bool bar = false;
int* p = nullptr;


const变量
#include <iostream>
using namespace std;

const double pi = 3.14159;
const char newline = '\n';

int main ()
{
  double r=5.0;               // radius
  double circle;

  circle = 2 * pi * r;
  cout << circle;
  cout << newline;

 

宏定义:

#include <iostream>
using namespace std;

#define PI 3.14159
#define NEWLINE '\n'

int main ()
{
  double r=5.0;               // radius
  double circle;

  circle = 2 * PI * r;
  cout << circle;
  cout << NEWLINE;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/YouXianMing/p/4316667.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值