Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a C program the OS creates an array of pointers to zero terminated strings. The count is passed as <code>argc</code> and the array is passed as <code>argv</code>. You already know this. The names <code>argc</code> and <code>argv</code> don't matter. You can use any name. The data types and the order do matter... <code>argv</code> must be <code>int</code> and <code>argc</code> must be <code>char*[]</code> or <code>char**</code>. Other languages have similar mechanisms. For example C# passes a single <code>string[]</code> argument which is a .NET array and keeps track of it's length internally. More information is available here: <a href="http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B" rel="nofollow">http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B</a></p> <p>Environment variable names are separate from names of variables in your program. <code>argc</code> and <code>argv</code> are not environment variables... they are variables local to <code>main()</code>.</p> <p>To access environment variables use <code>getenv()</code>.</p> <p><strong>Update:</strong> You wanted to know how these are made available to the program. It is the OS which does that. But before the OS can do so, the program invoking your executable -- the caller -- gets to process your command line. Usually the caller is a shell (<code>bash</code>, <code>csh</code>, <code>zsh</code>, <code>cmd.exe</code>) or a desktop environment like GNOME or Windows Explorer. The caller passes these arguments via <a href="http://linux.die.net/man/2/execve" rel="nofollow">execve</a> (on *nix) or <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx" rel="nofollow">CreateProcess</a> (on Windows).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload