[OCU] 예제로배우는 C언어 - 권기태 교수 (3주차)

Alpaca·2021년 3월 19일
0

C

목록 보기
1/2

C언어의 comment는

/*
multi line comment
multi line comment
multi line comment
*/

// one line comment

로 작성한다

functionblock이 필요한 것들은 반드시 indentation이 필요하다

#include <stdio.h>

int main(void)
{
	return 0;
}

indentation은 사용자의 가독성도 늘려주지만 compiler를 위해서 이기도하다

c언어에도 당연히 ANSI에서 지정한 reserved word가 있는데

auto
break
return
while
if
int

등이 있다

variablefunction의 이름은 영문자, 숫자, _(underscore)로 작성되며 첫 문자로 숫자가 올 수 없다

outputprintf()로 출력하는데 python과 다소 비슷한 것 같다

constants8진수0로 시작, 16진수0x로 시작한다

string을 출력할 때는 %c를 사용한다

printf('%c', 'hello world!')

10진수로 출력하려면 %d를 사용하는 등 서식을 정해줘야 한다

variabledeclaration은 변수의 자료형이름을 나열하여 표시
이름에 값을 assignment

int age = 20;
printf("%d\n", age);

이렇게 변수를 선언하고 값을 대입하고 출력할 수 있다
이를 함수로 표현해보면

#include <stdio.h>

int main(void)
{
    int age;
    age = 20;
    printf("내 나이는 %d살 입니다.", age);
    
    return 0;
}

// "내 나이는 20살 입니다."

이런식으로 나타낼 수 있다

profile
2020년 10월 15일 퇴사하고 개발자의 길에 도전합니다.

0개의 댓글