C++ primer 学习 一 类型

一 指针

1. 指针的声明

int *p // 此时的p是一个int型的指针
int *p = 0;// WA,because the p haven't be allocate the space
int *p,p1;// you must be attention that the p1 is the type of int,because the * only declocate the p

2. 通过指针的赋值

int *p = &a;
*p = 1; 
// through this way can we change the value of the a
*p++ // this ++ is made the to the p
(*p)++ // this ++ is made to the a

3 const 与 指针

* or const 都只是修饰的符号,如const int 修饰的是int ,int *const修饰的是后面的那个

const int a = 1; // in this way the a must be initlize and it can not be changed
const int *p = &a; // OK, the const int type point can point to the 
int *p = &a; // WA, because the int* cannot point to the const int
const int* const p2 = &a;// if we use the const to declocate the point,the point only point this value

我们可以用指向const int型的指针去指向一个int型的数字,但是这个int型的数是不难被这个改变的

int b;
const int* p3 = &b;

二 类型别名

我们通常使用typedef去处理我们的变量的别名

take something for example

typedef long long ll
// in this way the ll is the nickname of the long long ,and it is equal to the #define ll long long

三 Auto类型

auto i  = 0,*p = &i;
// if we use the auto to declare the varible, we do not need to worry about the type

四 decltype 类型

使用decltype类型去处理数据的时候,我们可以通过decltype(x) to get the type of the x

decltype(x) c = 0;
// the c is the same type of the x
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值