Main functions issue!

Main function contains some variables how it works , so far it has not been discussed , please explain sir !

hello @piyushkumar999999
those argument are called command line arguments.

image

  • argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for argument and one for program name)
  • The value of argc should be non negative.
  • argv(ARGument Vector) is array of character pointers listing all the arguments.
  • If argc is greater than zero,the array elements from argv[0] to argv[argc-1] will contain pointers to strings.
  • Argv[0] is the name of the program , After that till argv[argc-1] every element is command -line arguments.

btw we dont need them in any of our program.so u can use int main() only

Why in the output we are not adding ‘2’ twice and only once ??

which output ? if u r referring any particular code then pls share it with me

hi @piyushkumar999999 please tell if you have any further doubts?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.