whats the use of third argument to main( )

T

thesushant

hi,

whats the use of third argument to main( ), i.e. environmental
parameters.... if i am not wrong ? 1st 1 is argc 2nd is argv and what
bout the 3rd 1???????????

sushant
 
K

Keith Thompson

whats the use of third argument to main( ), i.e. environmental
parameters.... if i am not wrong ? 1st 1 is argc 2nd is argv and what
bout the 3rd 1???????????

The C standard specifies that main can take no arguments:
int main(void)
or two arguments:
int main(int argc, char **argv)

Implementations are allowed to accept other forms, but such forms are
non-standard and should probably be discussed in a newsgroup specific
to the system you're using.

One common extension is to accept a third argument that points to the
environment:
int main(int argc, char **argv, char **envp)

The standard getenv() function provides some, but not all, of the
functionality of this third argument. Some systems also make it
available as an external variable called "environ". It's a pointer to
an array of pointers to strings, each of the string represents an
environment variable.

Code intended to be maximally portable should only access the
environment through the getenv() function.
 
T

thesushant

thnx Keith for ur info .... can u elaborate on wht u mean by
environment variables?
 
M

Mike Wahler

thnx Keith for ur info .... can u elaborate on wht u mean by
environment variables?

Some, but not all, operating systems provide 'environment
variables' as a configuration mechanism, typically providing
'global' data available to applications. If your operating
system has them (e.g. MS-DOS and Windows have them), you
can learn more by reading its documentation.

-Mike
 
N

Neo

hi,

whats the use of third argument to main( ), i.e. environmental
parameters.... if i am not wrong ? 1st 1 is argc 2nd is argv and what
bout the 3rd 1???????????

sushant

main() can take at most two arguments.
int main(int argc, char *argv[])
{
.....
}

There no third argument to main() in C.
That can be some non-std. feature (implementation defined) which you may be
talking of. Sorry C doesnt have such thing.

-Neo
 
J

James McIninch

<posted & mailed>

hi,

whats the use of third argument to main( ), i.e. environmental
parameters.... if i am not wrong ? 1st 1 is argc 2nd is argv and what
bout the 3rd 1???????????

In C, main() takes at most 2 arguments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top