Menu
CoddyTech

헤더와 링키지

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

C#의 using은 어셈블리 내의 네임스페이스 이름을 가져옵니다. C 헤더는 번역 단위에 텍스트 선언을 제공하고, 링커는 정의를 확인합니다. include는 네임스페이스나 어셈블리 경계를 만들지 않습니다.

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

C# 예제

using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
class Program {
static class Text{public static string Bracket(string s){return "["+s+"]";}}
static void Main(){
Console.WriteLine(Text.Bracket("pen"));
}
}

C# 출력:

[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에서 비공개 정적 헬퍼 함수 multiply를 사용하세요. price와 count를 곱한 값을 반환하세요. 채점기는 헬퍼 함수의 작성 방식이 아니라 동작을 확인합니다.

잠금 해제된 소스 파일과 헤더 파일을 수정하세요. 보이는 잠금된 main.c에서 직접 호출하는 공개 API와 호환되도록 유지하세요. 다른 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실력 점검

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

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

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