int ia[]={ 0, 1, 2, 3, 4, 5};
for(size_t i=0;i!= 6;i++)
cout<<ia[i];
----------------------------------------------------------------------------------------------------------
int ival=1024,ival2=2048;
int *pi=&ival, *pi2=&ival2;
pi=pi2;
cout<<ival<<"/r/n";
cout<<ival2<<"/r/n";
cout<<*pi<<"/r/n";
cout<<*pi2<<"/r/n";
ival=1024,ival2=2048;
int &ri=ival, &ri2=ival2;
ri=ri2;
cout<<ival<<"/r/n";
cout<<ival2<<"/r/n";
cout<<ri<<"/r/n";
cout<<ri2<<"/r/n";
----------------------------------------------------------------------------------------------------------
Console result:
----------------------------------------------------------------------------------------------------------
1024
2048
2048
2048
2048
2048
2048
2048
----------------------------------------------------------------------------------------------------------
int ival=1024;
int *pi=&ival;
int **ppi=π
cout<<ival<<"/r/n";
cout<<*pi<<"/r/n";
cout<<**ppi<<"/r/n";
----------------------------------------------------------------------------------------------------------
Console result:
----------------------------------------------------------------------------------------------------------
1024
1024
1024
----------------------------------------------------------------------------------------------------------
const pointer point to a const value
----------------------------------------------------------------------------------------------------------
const double pi=3.14;
const double *cptr=π
double dval=3.14;
////*cptr=&dval; //error: *cptr might be const
cptr=&dval;//ok:but cannot change dval through cptr
dval=3.14159;
cout<<*cptr<<"/r/n";
cout<<dval<<"/r/n";
double *ptr=&dval;
*ptr=2.72;
cout<<*cptr<<"/r/n";
cout<<dval<<"/r/n";
----------------------------------------------------------------------------------------------------------
Console result:
----------------------------------------------------------------------------------------------------------
3.14159
3.14159
2.72
2.72
----------------------------------------------------------------------------------------------------------
typedef string *pstring;
const pstring cstr;
<==>
string *const cstr;
c style: #include <string.h>
c++ style: #include <cstring>
typedef int int_array[3];
int_array *ip=ia;
For(int_array *p = ia; o != ia+3; ++p)
{
for(int *q = *p; q != *p+4;++q)
{
cout<<*q;
}
}
----------------------------------------------------------------------------------------------------------
Terminology:
c-style string
Compiler extension
Compound type
Const void*
Delete expression
dimension
Dynamically allocated
Free store
heap
New expression
pointer
Pointer arithmetic
precedence
ptrdiff_t
Size_t
*opertator
++operator
[]operator
&operator
void*