????????漰C/C++?????????????????
//??????δ????????????????????
#include <stdio.h>
#include <stdlib.h>
#define HELLO_STRING "Hello World"
static void mem_alloc(char *p?? int size){
p = (char*)malloc(size);
}
int main(int argc?? char const *argv[])
{
char *ptr = NULL;
mem_alloc(ptr?? HELLO_STRING);
strcpy(ptr?? HELLO_STRING);
printf("String is %s "??ptr );
return 0;
}
?????????????????? δ?????????δ??????sizeof??strlen??????
????????????????????????????βν???????????????
????char *ptr = NULL;
????mem_alloc(ptr?? HELLO_STRING);
????strcpy(ptr?? HELLO_STRING);
????printf("String is %s "??ptr );
???????????mem_alloc()??????????ptr???????NULL??????????????????????????????????????????????????? ?δ??? ??
????????????????βδ????????????????????????????????????
?????????????????
#include <stdio.h>
void fun(int *p){
int b=100;
p=&b;
}
int main(int argc?? char const *argv[])
{
int a=10;
int *q=NULL;
q=&a;
printf("%d "?? *q);
fun(q);
printf("%d "?? *q);
return 0;
}
???????н???10 10
????q?????????и?????q??????????????fun()??fun()?е?p??????q?????????fun()?????????p?????100????????q???????????κα仯??
#include <stdio.h>
void fun(int *p){
*p=100;
}
int main(int argc?? char const *argv[])
{
int a=10;
int *q=NULL;
q=&a;
printf("%d "?? *q);
fun(&q);
printf("%d "?? *q);
return 0;
}
???????н???10 100???????????q?????????