✅ 목표 (Goal)

✅ 아래 코드는 에러가 날까?

안난다.

#include <stdio.h>

void woof() { // 강아지,멍멍
    printf("멍멍\\r\\n");
}

void meow() { // 고양이,야옹
    woof();
    printf("야옹\\r\\n");
}

int main() {
    woof();
    meow();
    return (0);
}

✅ 아래 코드는 에러가 날까?

난다. 왜?

(1)에서 meow() 함수가 정의되어 있지 않기 때문이다.

#include <stdio.h>

void woof() { // 강아지,멍멍
    meow(); // (1)
    printf("멍멍\\r\\n");
}

void meow() { // 고양이,야옹
    printf("야옹\\r\\n");
}

int main() {
    woof();
    meow();
    return (0);
}

✅ 어떻게 해결할까?

✅ 함수를 미리 정의하면 에러가 발생하지 않는다.

아래와 같이 호출하기 전에 컴파일러에게 함수를 알려주면 된다.

#include <stdio.h>

void meow() { // 고양이,야옹
    printf("야옹\\r\\n");
}

void woof() { // 강아지,멍멍
    meow();
    printf("멍멍\\r\\n");
}

int main() {
    woof();
    meow();
    return (0);
}