tags:

views:

255

answers:

2
+7  Q: 

argv[argc] == ?

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

-Jake

+24  A: 

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

Steve M
Why and how did it become standard? Any idea?
Reigel
@Reigel: The man page for `exec` from 1979 (http://plan9.bell-labs.com/7thEdMan/v7vol1.pdf) shows that this predates the standard by quite a bit, and contains a possible hint as to why it's this way: "Argv is directly usable in another execv because argv[argc] is 0."
bk1e
+20  A: 

From the Standard:

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

So, yes; argv is null terminated

pmg
It doesn't get more clear-cut than that ;)
caf