C
[C] 132 함수 포인터 사용하기
qkrwngus
2021. 1. 31. 00:17
Desc :
int(*myfunc)(const char*) : 함수 포인터 myfunc
정의한 반환형과 인자가 같은 함수를 대신하여 쓸 수 있게한다
int puts(const char*)
unsigned int strlen(const char*)
Source Code :
#include <stdio.h>
#include <string.h>
void main()
{
int(*myfunc)(const char*); // 함수포인터 변수, 반환형 int 인자로 char* 쓰는 모든 함수를 대신해서 사용가능
myfunc = puts;
puts("Hi");
myfunc("Bye"); // puts 함수처럼 사용
myfunc = strlen;
printf("문자열의 길이: %d\n", strlen("aa"));
printf("문자열의 길이: %d\n", myfunc("aa")); // strlen 함수처럼 사용
}
Result :