Skip to content

computerman2027/Parameter-list-C-program

Repository files navigation

C Method Signature Examples

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.

Files

  • 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
  • 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
  • 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

Outputs

  • outputNoParameterList.txt → Output of noparameterlist.c
  • outputParameterList1.txt → Output of parameterlist2.c with no arguments
  • outputParameterList2.txt → Output of parameterlist2.c with arguments
  • outputParameterListwithEnv1.txt → Output of parameterlistwithenv.c with arguments
  • outputParameterListwithEnv2.txt → Output of parameterlistwithenv.c with arguments + custom environment variable

Notes

  • 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 form NAME=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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages