기본 콘텐츠로 건너뛰기

main()

 1 /*
 2     Hello World
 3 */
 4 
 5 #include <stdio.h>
 6 
 7 int main(void)
 8 {
 9     printf("Hello World \n");
10     return 0;
11 }


1~3
주석문은 /*과 */ 사이에 표현되며 프로그램의 기능을 설명하는 내용을 적는다. 프로그램에는 아무런 영향도 미치지 않는다.

5
전처리기(preprocessor)는 #으로 시작되며, 컴파일을 하기 전에 먼저 수행하라는 기호이다.
따라서, 컴파일 하기 전에 stdio.h라는 표준입출력 함수 헤더 파일을 포함시키게 된다. stdio.h에는 printf() 함수에 대한 원형이 선언되어 있다.

7~11
C 프로그램은 반드시 하나 이상의 함수를 포함하게 되며, main() 함수는 반드시 존재해야 한다.

프로그램의 실행은 메인 함수로부터 시작되며, 메인 함수가 끝날 때 프로그램이 종료된다.
함수의 시작과 끝은 중괄호 { }로 묶여지며, 중괄호 안에는 변수 선언문, 치환, 연산, 함수 등의 명령을 기입한다.

9, 10
세미콜론(;)은 한 문장의 끝을 의미한다. 전처리기를 제외한 모든 문장의 끝에는 세미콜론(;)이 사용된다.

10
return은 함수를 종료하고 값을 반환한다. 메인 함수는 운영체제에게 값을 반환한다.

댓글

이 블로그의 인기 게시물

C 표준, GCC 그리고 컴파일 옵션

GCC supports three versions of the C standard, although support for the most recent version is not yet complete. The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. This standard, in both its forms, is commonly known as  C89 , or occasionally as  C90 , from the dates of ratification. The ANSI standard, but not the ISO standard, also came with a Rationale document. To select this standard in GCC, use one of the options  -ansi ,  -std=c90  or  -std=iso9899:1990 ; to obtain all the diagnostics required by the standard, you should also specify  -pedantic  (or  -pedantic-errors  if you want them to be errors rather than warnings). See  Options Controlling C Dialect . Errors in the 1990 ISO C standard were cor

연산자 우선 순위

() (괄호) [] (배열) -> (포인터멤버) . (구조체멤버) ! (부정) ~ (1의보수) ++ (증가) -- (감소) - (부호)  + (부호)  (자료형) (형변환)  * (포인터)  & (주소)  sizeof * (곱셈) / (나눗셈) % (나머지) + (덧셈) - (뺄셈) << >> (비트이동) < <= > >= (관계) == != (관계) & (비트논리곱) ^ (비트배타논리합) | ( 비트논리합 ) && (논리곱) || (논리합) ?: (조건) = (할당) += -= *= /= %= &= ^= |= <<= >>= (복합할당) , (쉼표)

errno.h

errno.h 파일에는 오류 코드를 기억할 수 있는 errno가 매크로로 정의되어 있고, 그 외에 각종 오류 코드 넘버들이 매크로 상수로 정의되어 있다. 프로그램 시작시에는 errno의 값이 0으로 초기화되며, 특정 오류가 발생한 때에는 이 값이 해당 오류 코드로 바뀐다. 프로그램에서도 이 값을 읽거나 수정할 수 있다. #include   <stdio.h> #include   <errno.h> int   main () {           printf ( "%d\n"   , errno);        errno = ENOMEM;           printf ( "%d\n"   , errno);           return   0; }