Development/Linux

[Linux] C/C++ - Command line argument (명령행 인자)

oneonlee 2022. 4. 17. 20:29
반응형

Command line argument

1. main() with command line arguments.

ex1.c:

int main(int *x, char *y[]){
   .............
}

The system will pass

  • x: command line arguments의 개수 (아래 예제에서 3개가 아니라 4개임에 유의)
  • y: command line argument

For example,

$ ./ex1 x1 x2 x3

will pass 4 command line arguments: ./ex1, x1, x2, x3.

 

Therefore, the system will pass

  • x <-- 4 (number of command line arguments)
  • y[0] <-- ./ex1 (first command line argument)
  • y[1] <-- x1 (second command line argument)
  • y[2] <-- x2 (third command line argument)
  • y[3] <-- x3 (fourth command line argument)

 

추가적인 예제 및 실습 문제들을 확인하고 싶으시면 아래 링크를 클릭해주세요 :)

 

GitHub - oneonlee/Computer-Science: Introduction to Computer Science

Introduction to Computer Science. Contribute to oneonlee/Computer-Science development by creating an account on GitHub.

github.com

 

반응형