This repository contains simple C programs demonstrating different forms of the main
function signature in C, and how command-line arguments and environment variables are handled.
-
noparameterlist.c
- Demonstrates
int main(void)
- No external input is taken, only prints internal messages.
- Run example:
gcc noparameterlist.c -o noparameter ./noparameter > outputNoParameterList.txt ./noparameter hi hope > outputNoParameterList.txt
- Demonstrates
-
parameterlist2.c
- Demonstrates
int main(int argc, char *argv[])
- Accepts command-line arguments and prints them.
- Run example:
gcc parameterlist2.c -o param2 ./param2 hi this is a ball 73 62 > outputParameterList2.txt ./param2 > outputParameterList1.txt
- Demonstrates
-
parameterlistwithenv.c
- Demonstrates
int main(int argc, char *argv[], char *envp[])
- Prints command-line arguments and environment variables.
- Run example:
gcc parameterlistwithenv.c -o paramenv MYVAR=Hello ./paramenv hi this is a ball 73 62 > outputParameterListwithEnv2.txt ./paramenv hi this is a ball 73 62 > outputParameterListwithEnv1.txt
- Demonstrates
outputNoParameterList.txt
→ Output ofnoparameterlist.c
outputParameterList1.txt
→ Output ofparameterlist2.c
with no argumentsoutputParameterList2.txt
→ Output ofparameterlist2.c
with argumentsoutputParameterListwithEnv1.txt
→ Output ofparameterlistwithenv.c
with argumentsoutputParameterListwithEnv2.txt
→ Output ofparameterlistwithenv.c
with arguments + custom environment variable
argc
is the count of arguments.argv
is the list of command-line arguments (argv[0]
= program name).envp
is the list of environment variables in the formNAME=VALUE
.- Always loop using
i < argc
to avoid undefined behavior.
✅ This repository is useful for understanding different signatures of main
in C and how to work with external and internal inputs.