Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

argv[argc] ==?

Tags:

c

argv

My professor and a couple of students are arguing about whether argv is null terminated or not. My friend wrote a small program and it printed out null but another kid said that he is probably simply reading into blank memory. Can someone solve this discussion?

like image 608
jakehschwartz Avatar asked Sep 22 '10 19:09

jakehschwartz


People also ask

What is argv and argc?

The first parameter, argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started. The second parameter, argv (argument vector), is an array of pointers to arrays of character objects.

What does argc == 2 mean?

argc is the count of arguments, and argv is an array of the strings. The program itself is the first argument, argv[0] , so argc is always at least 1. So, argc is 2 when the program is run with one command-line argument.

What does int argc char * argv [] do?

The argc parameter represents the number of command line arguments, and char *argv[] is an array of strings (character pointers) representing the individual arguments provided on the command line.

Why argv argc is a null pointer?

— argv[argc] shall be a null pointer. The rationale for this is to provide a redundant check for the end of the argument list, on the basis of common practice (ref: Rationale for the ANSI C programming language (1990), 2.1. 2.2).


2 Answers

From the Standard:

5.1.2.2.1 Program startup
...
-- argv[argc] shall be a null pointer.

So, yes; argv is null terminated

like image 85
pmg Avatar answered Sep 20 '22 19:09

pmg


According to the standard, "argv[argc] shall be a null pointer" (5.1.2.2.1).

like image 26
Steve M Avatar answered Sep 23 '22 19:09

Steve M