Menu
CoddyTech

헤더와 링키지

Coddy의 Go 개발자를 위한 C 코스 레슨. 48개 중 18번째.

Go 패키지는 패키지 이름과 대문자 표기를 통해 선언을 컴파일하고 내보냅니다. C 헤더는 번역 단위 간에 공유되는 텍스트 형식의 인터페이스 선언이며, 인클루드 가드와 외부 연결이 패키지 메커니즘을 대신합니다.

헤더는 번역 단위 간에 공유되는 인터페이스를 선언합니다. 인클루드 가드는 선언이 반복되는 것을 방지하며, 정의는 소스 파일에 둡니다.

Go 예제

package main
import ("fmt")
func bracket(s string)string{return "["+s+"]"}
func main(){
fmt.Println(bracket("pen"))
}

Go 출력:

[pen]

C 예제

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
static int total(int price,int count){return price*count;}
int main(void) {
printf("%d\n",total(3,4));
return 0;
}

C 출력:

12
challenge icon

챌린지

쉬움

lesson.h에 공개 함수로 subtotal(price,count)를 선언해 구현하세요. 필요하다면 lesson.c에서 비공개 static multiply 헬퍼를 사용하세요. price와 count를 곱한 값을 반환하세요. 채점기는 헬퍼의 작성 방식이 아니라 동작을 확인합니다.

잠금 해제된 소스 파일과 헤더 파일을 수정하세요. 공개 API 선언은 이를 직접 호출하는 잠긴 main.c와 호환되도록 유지하세요. 또 다른 main을 추가하지 마세요. 작업의 모든 숫자 테스트 데이터는 작업에서 특정 범위를 확인한다고 명시하지 않는 한 오버플로가 발생하지 않을 만큼 작습니다. 지정된 출력만 출력하세요. 드라이버가 입력 파싱과 출력을 제공하는 경우도 있습니다.

직접 해보기

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
#include "lesson.h"
int main(void){int a=0,b=0;if(scanf("%d%d",&a,&b)!=2)return 1;printf("%d\n",subtotal(a,b));return 0;}
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Go 개발자를 위한 C의 모든 레슨

직접 연습해 보세요: 온라인 C 컴파일러