//基础
void fun(int* a){
cout<<sizeof(a)<<'\n';
}
int main(){
// int a=10; int* p=&a;
// a==*p;//true
// void* pp;
// pp =&a;
// cout<<pp<<'\n';
// cout<<p+1<<'\n';
// cout<<p;
//用于函数传址调用 test(int* p// int &p)
int A[5]={1,2,3,4,5};
fun(A);
int* p;
cout<<sizeof(p);
}
void fun(char a[10]){
//char a[N]在函数传入==char* 类型,大小8 bite
}
int main(){
// %s c语言string为char[]都要以/0结尾
char c[3]; c[0]='C',c[1]='h';c[2]='\0';
char a[]="Ch";
//cout<<sizeof(a);//3
//*(a+1)='a' == a[1]='a'
// 2维数组 //
int s[2][3]; s[0][0]=11;
int (*p)[3]=s;
//*p,*s指向一维数组,sizeof(p)==8 != sizeof(s);
// s=p=*S=&s=&s[0]=&s[0][0];首元素地址
// p!= &p 除此之外p和s完全等价,且p[i]=&p[i]
//s+1=*(s+1)=s[1]=&s[1]=&s[1][0]
//但(s+1)+1 != *(s+1)+1 == s[1]+1=&s[1][1];
//
printf("%d\n", &s[1][1]);
printf("%d\n", *(s+1)+1);
printf("%d\n", s[1]+1);
}
// 内存 //
struct node{
int data;
};//code(text)
const int N=1e5;//static/global
int main(){
//栈区stack 函数栈帧(后进先出)
//堆区heap 需要手动释放
node* a = new node;
node*b = (node*) malloc(sizeof(node));
delete a; free(b);
//malloc calloc realloc
//void* realloc( void* ptr, size)
}
// 函数指针 //
template<class T>
auto func(T a, T b){
auto c=a+b;
return c;
}
void A(){ cout<<"Hello"<<'\n'; }
void B(void (*p)()){ p(); }
int main(){
double (*p)(double, double);//一致
p = &func;// p = func;
double c= (*p)(1, 3);
cout<<c<<'\n';
void (*ptr)(); ptr=A;
B(A);//回调函数
B(ptr);
//sort(_begin, _end, func)这就是回调func
}
//关于内存
//二维数组
int**p = (int**) malloc(n*sizeof(int));
for(int i=0;i<n;i++){
p[i] = (int*) malloc(n*sizeof(int));
}
int **p = new int*[n];
for(int i=0;i<n;i++){
p[i] = new int[n];
}