#include <stdio.h>
#include <stdlib.h>
// 두개 함수의 차이를 알자
// int *f1(int, int *) : int *를 반환하는 함수
// int *(*fp)(int, int *) : 그런 함수를 가리키는 함수 포인터
int *f1(int, int*); //int형 포인터를 반환하는 함수
int main(void) {
int *t = NULL; //아무 곳도 가리키지 않는다”는 의미의 NULL 값이 저장, 메모리할당은 int 사이즈만큼 받음
t = f1(0,t);
*t = *t+20;
t = f1(1,t);
free(t);
}
int *f1(int tag, int *p) {
// int a = 0;
int static a = 0;
int s = 0;
if(tag == 0){
p=(int *)malloc(sizeof(int));
*p = 0;
}
a=a+2;
s=s+a;
printf("%d ",s);
*p = *p+10;
s=s+*p;
printf("%d ",s);
return p;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: