Basic C Language / C 언어

Geewon Kim·2024년 1월 14일

Clang

목록 보기
1/13

why C

OS 개발을 위해 개발된 언어로 간단한 문법, 적은 기능이 특징이다.
주로 PC, 마이크로 컨트롤러, 임베디드 개발 등에 사용된다.
기계제어 분야에서 특히 많이 사용되기 때문에 하드웨어와 어셈블리어 까지도 함께 활용하는 경우가 많다.

C 의 Build

C의 빌드는 4단계

  • Preprocessing/전처리(.i)
    소스파일로 변환하는 단계.
    주석의 제거, header include, library include 등..
  • Compiling/컴파일(.s, .S)
    Assembly 형태의 데이터를 담은 파일 생성
  • Assembling/어셈블(.o)
    C 코드를 모으고 각 소스의 데이터와 기계어를 모은 Binary 형태의 파일 생성
  • Linking/링크(.exe)
    최종 프로그램

전처리, 컴파일, 어셈블을 합쳐서 컴파일이라고 하기도 하고, 컴파일 어셈블을 합쳐서 컴파일이라고 하기도 한다.

Build

GNU 명령어, GCC를 이용함

Source sample.c

int main(void)
{
    return 0;
}

GCC Compiler

  • syntax errors, wrong answers check

  • sample.c -> sample.o

    $ gcc sample.c
    $ ./sample.o
  • sample.c -> sample.o -> sample.exe

    $ gcc -o sample.exe sample.c

example of add function

#include <stdio.h>

int main(void)
{
    float sum, a, b;
    printf("Input A and B\n :");
    scanf("%f%f", &a, &b);
    sum = a + b;
    printf("%f + %f = %f\n", a, b, sum);
    return 0;
}

example of circle function

  • lf for double
#include <stdio.h>

#define PI (3.141592)


int main()
{
    double area, radius = 0.f;

    printf("input radius\n");
    scanf("%lf", &radius);

    area = PI * radius * radius;
    printf("The radius of the circle is %f\n", radius);
    printf("The Answer is %f\n", area);

    return 0;
}
profile
내 지식의 외장하드

0개의 댓글