c++ pointer

1.pointer must be initialized

2.*a=&b,address of b=>a

3.all points needs 4 bytes. short*p=&b,means type b needs 2 bytes

4.*p=&b: b addr=>p value;b=*p:value that p points to =>b;*p=5:5=>value at p points to   *p=0:void pointer

5.after pointer declaritino:p=&b,works,just like type,”short *” is a type

6.memory:stack,global storage,code area,register(stack-top pointer or instructive pointer),the rest is heap

7.stack can be released automatically,but heap needs to be released by person

8.new:allocate memory for heap;new returns address,so p=new int;

9.p=new int;=>delete p(p still exists,but not point to memeroy anymore;=>p=0;delete p(delete void pointer)

10.create new object/new pointer=>call constructor;delete pointer/working range ends=>call destructor

11.member function: object.getage() is equal to p->getage()

12.const int*p: the value at p can not be changed;int * const p:the address stored in p can not be changed

13.cin.getline(buffer,buffersize)to get the input string

14.isanum():Tests whether an element in a locale is an alphabetic or a numeric character.

15.if after you called a function,you wanna keep the value of variable,pointer or reference as parameter,which means you can change the value in the function,such as:GetWord(char* theString,char* word,int & wordOffset)

16.const int * p: p is a pointer who points to an int variable.and the variable can not be changed by pointer.int* const p:p is a pointer who points to an integer.and this pointer can not be assigned again.

Leave a comment