argc (argument count), argv (argument vector)
int main ()
int main ( void )
int main ( int argc, char ** argv )
argc, argv๋ ๋ช ๋ นํ๋กฌํํธ์์ ๋ช ๋ น์ด๋ฅผ ์ณค์ ๋ ์ธ์๋ฅผ ๋ด์ ๋ฐฐ์ด์ด๋ค.
argc : the number of strings pointed to by argv (number of arguments + 1)
argv : the array of arguments
Running it with ./test a1 b2 c3 will output:
Have 4 arguments:
./test
a1
b2
c3
โป char ** argv VS. char * argv[]
char** argv: pointer to a pointer to a char
char* argv[]: pointer to an array
"The name of an array is a pointer to the first element of the array."
char text[] = "A string of characters.";
์์์ "text" ๋ณ์๋ char * type์ด๋ค.
[index]๋ฅผ ์ฌ์ฉํ์ฌ ํ array์ element์ ์ ๊ทผํ ๋, ์ค์ ๋ก๋ ๋ณ์์ ๋ฐ์ดํฐํ์ ๊ทธ๋๋ก ๊ฐ์ ธ์ค๋ ๊ฒ์ด ์๋๋ผ index์ offset์ ํ๋ ฌ์ ์ฒซ๋ฒ์งธ ์์์ ํฌ์ธํฐ์ ๋ํ๊ณ ๊ทธ ์ฃผ์๋ฅผ (=ํฌ์ธํฐ) ๊ฐ์ ธ์ค๋ ๊ฒ์ด๋ค.
ํฌ์ธํฐ๋ ๋ค๋ฅธ ๋ณ์ ํน์ ๊ทธ ๋ณ์์ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ฃผ์๋ฅผ ๊ฐ๋ฆฌํค๋ ๋ณ์๋ฅผ ๋งํ๋ค.
ํฌ์ธํฐ๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ์ ๊ฐ์ ธ์ค๋ ๊ฒ์ ์ญ์ฐธ์กฐ(direferencing)๋ผ๊ณ ํ๋ค.
'ํ๋ก๊ทธ๋๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๋ฆฌ๋ ์ค ๋ช ๋ น์ด Linux Commands (0) | 2015.03.16 |
|---|---|
| ์ ํ๋ฐฉ์ ์์ ๋ฐ๋ณตํด๋ฒ Iterative Methods for Solving Linear Systems (1) | 2015.03.11 |
| ์ ์ฒ๋ฆฌ ์ง์์ Preprocessor Directive (0) | 2015.03.09 |
| [tbd] Jos Stam, Stable Fluids (1999) (0) | 2015.03.06 |
| [tbd] ๋ณ๋ ฌ ์ปดํจํ Parallel Computing (0) | 2015.03.05 |