The C standard says following about main function in C.
The function called at program startup is named main. The
implementation declares no prototype for this function. It shall
be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though
any names may be used, as they are local to the function in which
they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;10) or in some other implementation-defined manner.
But most of the compilers also support a third declaration of main that accepts third argument. The third argument stores all environment variables.
#include <stdio.h> // Most of the C compilers support a third parameter to main which // store all envorinment variables int main(int argc, char *argv[], char * envp[]) { int i; for (i = 0; envp[i] != NULL; i++) printf("\n%s", envp[i]); getchar(); return 0; } |
chevron_right
filter_none
Output:
ALLUSERSPROFILE=C:\ProgramData CommonProgramFiles=C:\Program Files\Common Files HOMEDRIVE=C: NUMBER_OF_PROCESSORS=2 OS=Windows_NT PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 42 Stepping 7, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=2a07 ProgramData=C:\ProgramData ProgramFiles=C:\Program Files PUBLIC=C:\Users\Public SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\Windows WATCOM=C:\watcom windir=C:\Windows
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Difference between Static variables and Register variables in C
- Setting up C++ Development Environment
- How will you show memory representation of C variables?
- How are variables scoped in C - Static or Dynamic?
- What are the default values of static variables in C?
- Operations on struct variables in C
- Initialization of static variables in C
- Initialization of variables sized arrays in C
- Initialization of global and static variables in C
- Static Variables in C
- Constants vs Variables in C language
- Problem Solving on Storage Classes and Scoping of Variables
- Linking Files having same variables with different data types in C
- Implicit initialization of variables with 0 or 1 in C
- Can Global Variables be dangerous ?
- Why do we need reference variables if we have pointers
- Difference between Identifiers and Variables in C
- Variables and Keywords in C
- Swap two variables in one line
- C program to print a string without any quote (singe or double) in the program

