Week3 Lecture: A student asked a question of my mind how do computer know about the argc ? I really don't understand how is this argc working In case we printed "zymla" we gave argv[1] as our first command was hello-4 and second was zymla Where is the role of "argc" ?
1 Answer
If I understand your question correctly, and it's "what is the role of argc
" the answer is that we need it to know how many arguments were passed to main
from the command line. So if the command was ./hello-4 Zamyla
we have argc == 2
and argv[0] == "./hello-4"
and argv[1] == "Zamyla"
. Without argc
you wouldn't know the length of argv
.