C
언어의 comment는
/*
multi line comment
multi line comment
multi line comment
*/
// one line comment
로 작성한다
function
등 block
이 필요한 것들은 반드시 indentation
이 필요하다
#include <stdio.h>
int main(void)
{
return 0;
}
indentation
은 사용자의 가독성도 늘려주지만 compiler
를 위해서 이기도하다
c
언어에도 당연히 ANSI
에서 지정한 reserved word
가 있는데
auto
break
return
while
if
int
등이 있다
variable
과 function
의 이름은 영문자, 숫자, _(underscore)로 작성되며 첫 문자로 숫자가 올 수 없다
output
은 printf()
로 출력하는데 python
과 다소 비슷한 것 같다
constants
중 8진수
는 0
로 시작, 16진수
는 0x
로 시작한다
string
을 출력할 때는 %c
를 사용한다
printf('%c', 'hello world!')
10진수
로 출력하려면 %d
를 사용하는 등 서식을 정해줘야 한다
variable
의 declaration
은 변수의 자료형
과 이름
을 나열하여 표시
이름
에 값을 assignment
int age = 20;
printf("%d\n", age);
이렇게 변수를 선언하고 값을 대입하고 출력할 수 있다
이를 함수로 표현해보면
#include <stdio.h>
int main(void)
{
int age;
age = 20;
printf("내 나이는 %d살 입니다.", age);
return 0;
}
// "내 나이는 20살 입니다."
이런식으로 나타낼 수 있다