C Program to print environment variables Last Updated : 17 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. C #include <stdio.h> // Most of the C compilers support a third parameter to main which // store all environment 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; } 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 Comment More infoAdvertise with us Next Article C Program to print environment variables K kartik Follow Improve Article Tags : C Language C Basics Similar Reads Printing source code of a C program itself Printing the source code of a C program itself is different from the Quine problem. Here we need to modify any C program in a way that it prints the whole source code. Recommended: Please try your approach on {IDE} first, before moving on to the solution.ApproachUse predefined macro __FILE__ to get 2 min read How to avoid Compile Error while defining Variables Variables: A variable is the name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory locati 3 min read Different ways to declare variable as constant in C There are many different ways to make the variable as constant in C. Some of the popular ones are: Using const KeywordUsing MacrosUsing enum Keyword1. Using const KeywordThe const keyword specifies that a variable or object value is constant and can't be modified at the compilation time. Syntaxconst 2 min read Common Memory/Pointer Related bug in C Programs Dereferencing an unknown memory location : C programmers mostly use scanf() function to take input, but sometimes a small mistake can bring a bug or even crash whole program. The syntax for scanf() is scanf("%d", &a);. It might be possible to miss a & and write &a as a so now scanf("%d", 6 min read Local Variable in C In C language, a variable declared within a function or a block of code is called a local variable. Local variables are frequently used to temporarily store data in a defined scope where they can be accessed and manipulated. They are stored in the memory stack, Once the function or block of code in 3 min read Like