프로그래밍 언어/C·C++
const and pointer
const는 declaration specifier 로도 사용할 수 있고, declarator의 일부로도 사용할 수 있다. 1. const as a declaration specifier int x = 1, y = 2; const int *p = &x; // int const *p = &x; 여기서 const 는 declaration specifier 로 사용되었다. 이 때, *p는 const int 가 된다. 즉, p는 const int에 대한 포인터가 된다. 따라서, p = &y; // O *p = 3; // X 2. const in a declarator int x = 1, y = 2; int *const p = &x; 여기서 const 는 *와 함께 delarator 의 일부로 사용되었다. 이 때..

선언이란? (feat. Array and Pointer)
C언어에서 선언은 다음과 같이 구성된다. [declaration specifiers] [list of (possibly initialized) declarators] ; 예를 들어, unsigned long int a[10]={0}, *p=NULL, f(void); 에서 • unsigned long int : declaration specifiers • a[10] = {0}, *p = NULL, f(void) : declarator 가 된다. 이 때, declarator는 변수의 이름, array-ness, pointer-ness, function-ness를 나타내게 된다. 그런 의미에서 int* p; 보다는 int *p; 가 더 좋은 표기법이다. declarator는 실제로 변수를 사용하는 방법을 모방..

Command Line Arguments
#include int main(int argc, char const *argv[]) { if(argc == 1){ printf("Error : no command line arguments!\n"); return 1; } printf("Hello, %s\n", argv[0]); printf("Hello, %s\n", argv[1]); return 0; } argc : argument count argv : argument vector argv[0] : program name argv[1] ~ : arguments passed to the program

hello.c가 hello.exe가 되기까지
/* hello.c */ #include "test.h" int main() { sum(3, 4); return 0; } /* test.h */ void sum(int a, int b); /* hello.c */ #include "test.h" int main() { sum(3, 4); return 0; } 위와 같은 상황에서 hello.c는 네 가지 과정을 거쳐 실행파일이 된다. I. 전처리 #include, #define 같은 명령어들을 처리해준다. #include를 처리할 땐 헤더파일을 그대로 가져와서 코드에 넣어준다. 실험 옵션 -E : 전처리까지만 수행 -o : 결과 파일 이름 지정 II. 컴파일링 어셈블리어로 번역한다. 실험 옵션 -S : 컴파일링까지만 수행 III. 어셈블링 기계어로 번역한다..