I understand what these arguments do--take inputs before the program starts to in some way influence the program. But they seem to have been shoe-horned into the lecture. David moves on from this topic to talk about cryptography and encryption, but that jump is seemingly random and unlinked to any of the previous material. Why does he explain these arguments at all--what is the link to the rest of the lecture? More broadly, I think this may be due to a misunderstanding about what the main() function fundamentally does--I still see it as just a piece of syntax that you have to put at the top to make the program work, so perhaps addressing that question is a way to understand why David outlines the roles of these arguments in the first place?

Thank you--a beginner learning to code!

  • Have you attempted the pset? Assuming you haven't, you'd probably find the "link" between cryptography and argc and argv once you attempt even one of the problems. Let me know if you still have any doubts. Good luck! Commented Jul 11, 2019 at 15:23

1 Answer 1


What do argc and argv have to do with the subject of cryptography? Nothing.

But they DO have a lot to do with how you get data into a program when it is started. Just in case you didn't comprehend it, here's what those two items do.

argc is a built-in variable in C, one of the few. It tells the program the number of parameters that were in the call to the program. It will always be at least 1. (I'll explain shortly.)

argv[] is an array. Specifically, it is an array of strings. Each string is a char array in itself. The argv[] array will always have at least one element. That element is argv[0], and will contain the string that started the program. Each element of the array that follows will be a parameter in the command line.

For example, say that you execute the following program:

./foobar test 21  "I'm a program"

This will cause argc to be set to 4 and the argv array will be: argv[0]:./foobar argv[1]:test argv[2]:21 argv[3]:I'm a program

Each of these is a string. Note in particular that argv[2] is not an int or any kind of number. It's the string containing two characters, 2 and 1. Next, argv[3] is also a string, but it contains spaces. Since it was put in quotes, it was treated as one string, not 3 strings separated by spaces.

Now, why was it presented in the lecture as it was? It's time to present the standard format of creating a main() program and to teach how to pass data into the program at execution call time. It has to be presented now.

Also, you're getting a lot of information thrown at you at once. It's going to be like trying to drink water from a fire hose! Time to get used to it! ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .