C++ relearning

C++ relearning

typedef

use typedef to give a specific type a nickname

typedef int feet;
feet distance;//completely equate 'int distance;'

enum

It is used to declare some constant quantities. It’s more than useful in defying some specific constants.

enum color { red, green, blue } c;
c = blue;
// In the default state, these constants are valued from 0,1,2...
// If we do give some constant a initial value, then comes the following circumstances.
enum color { red, green=5, blue };
// That means red == 0, green == 5, blue == 6 (blue is defaultedly valued green + 1)

extern

define a variable ,then declare this variable in different subprograms.

extern int a;
int a;

static

‘static’ is used to order the compiler to keep the variable alive, so that the variable will not be created and destroyed (its value won’t change) during the process of calling the function.

When it’s used to declare a global variable, the specific variable can only be used in the programme.

static int count = 10;

register

‘register’ is used to declare variables in the computer register, not in the RAM. The variable can not be applied using ‘&’(because it’s not in the memory).

computer register can only be used to store variables that needs quick access.

Notes: When using ‘register’ to declare a variable, the variable is stored in the register is not a must, it actually depend on the limitation of hardware and implement.

register int a;

thread

thread 线程

default 默认

pointer

A pointer’s value is the address of the variable.

//when there is not a specific address for the pointer to store. It's a good idea to let the pointer point to NULL(a special constant valued 0)
int *ip = NULL;
//* : get the value of a pointer
//& : get the address of a variable
int var = 20;
ip = &var;
cout << ip << endl << *ip << endl;
//move sizeof(int) btye address(eg: before: ip=1000, after : ip=1004)
ip++;


//a pointer and an array
int arr[10];
//the following two ways are equivilent
ip = &arr[0];
ip = arr;
//pass an array pointer parameter
int GetContent(int *arr);
int GetContent(int arr[]);

//ptr:an address; *ptr: a variable
char *ptr = "fdhsjkhfdaskdfa";
cout << ptr << endl << *ptr << endl;

Classes and inheritance

class is just like struct,

here is the difference:

During the process as inheritance,

class default as private while struct default as public

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值