Constants and modifier types in C++

Modifier type:

Unsigned

Signed

long

short

Constant: Refers to the value that does not change during operation.

0123 //octal

0x3a //Hexadecimal

U23 //Unsigned integer

234ul //Unsigned long integer (the case and position of u and L can be interchanged)

Integer constant: It can be decimal, hexadecimal or octal. The octal is represented by 0, and 0x is the hexadecimal.

Boolean constant: only two values. true or false

Character constants: all translated characters are constants

Floating-point constants: mainly integer + decimal point + decimal part + exponent part

3.14159 // Legal

314159E-5L // legal

In C++, there are two simple ways to define constants:

#define WIDTH 5 (similar to C language macros)

Modified with const

#include <iostream>
using namespace std;
 
#define LENGTH 10   
#define WIDTH  5
#define NEWLINE '\n'
 
int main()
{
 
   int area;  
   
   area = LENGTH * WIDTH;
   cout << area;
   cout << NEWLINE;
   return 0;
}


#define 定义的是宏,在main外面定义。const 一般在函数里面定义。

 

Guess you like

Origin blog.csdn.net/zhuiyunzhugang/article/details/111477161