1.demo1
#include <stdio.h>
typedef struct my{
int tan;
int kai;
//struct my * next;
}mystruct;
void test(mystruct *tk);
void test1(mystruct **tk1);
int main(){
mystruct list[128];
//list = (mystruct *)malloc(sizeof(mystruct));
//list->tan = 1;
//list->kai = 1;
//list->next = NULL;
list[0].tan = 1;
list[0].kai = 1;
printf("list is 0x%lx\n",list);
printf("list[0].tan is %d\n",list[0].tan);
printf("list[0].kai is %d\n",list[0].kai);
printf("&list is 0x%lx\n",&list);
test(list);
printf("list is 0x%lx\n",list);
printf("list[1].tan is %d\n",list[1].tan);
printf("list[1].kai is %d\n",list[1].kai);
//char *b = NULL;
//b = (char)malloc
//int b = 1;
//printf("&b is 0x %lx\n",&b);
//int *c = &b;
//printf("c is 0x %lx\n",c);
//test(c);
//printf("*c is %d\n",*c);
return 0;
}
void test(mystruct *tk){
//printf("tk is ox%lx\n",tk);
//tk ++;
//printf("tk is 0x%lx\n",tk);
//printf("*tk is 0x %lx\n",*tk);
//tk->tan = 2;
//tk->kai = 2;
//printf("result \n");
test1(&tk);
//tk[2].tan = 2;
//tk[2].kai = 2;
//printf("tk is 0x%lx\n",tk);
//printf("&tk is 0x%lx\n",&tk);
//*a = 2;
}
void test1(mystruct **tk1){
(*tk1) += 1;
(*tk1)->tan = 2;
(*tk1)->kai =2 ;
}
gcc -o 1 1.c
list is 0x7fffc736bed0
list[0].tan is 1
list[0].kai is 1
&list is 0x7fffc736bed0
list is 0x7fffc736bed0
list[1].tan is 2
list[1].kai is 2
2.demo2
#include <stdio.h>
void test(char **b);
int main(){
char * a = NULL;
a = (char *)malloc(sizeof(char));
printf("a is 0x%lx\n",a);
test(&a);
printf("a is 0x%lx\n",a);
}
void test(char **b){
printf("*b is 0x%lx\n",*b);
*b = (char*)malloc(sizeof(char));
printf("*b is 0x%lx\n",*b);
}
gcc -o 2 2.c
a is 0x74f010
*b is 0x74f010
*b is 0x74f030
a is 0x74f030
3.demo3
vi 3.c
#include <stdio.h>
void mymalloc(char **a);
void myfree(char **a);
int main()
{
char *a = NULL;
mymalloc(&a);
printf("a is 0x%x,strlen(a) is %d\n",a,strlen(a));
myfree(&a);
return 0;
}
void mymalloc(char **a)
{
*a = (char *)malloc(10);
strcpy(*a,"adbcde");
}
void myfree(char **a)
{
free(*a);
}
gcc -g -o 3 3.c
a is 0x16e8010,strlen(a) is 6