Registration is free. Click here to register now. Register Log in. JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding. You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser. What's the meaning of 'argc' and 'argv' in C Language? Thread starter elec-eng Start date Aug 17, Status Not open for further replies.
Please help me i cant understand the meaning of 'argc' and 'argv' in the C Language and what are there functions thank. C Language help argc and argv are used when you are starting a program from the command line, or want to pass some variables to the program. Dates back a bit! For example, if you had a program called 'squareroot'. You could call it by: squareroot 4 squareroot would have 2 in argc and two pointers, one to "squareroot" and one to "4" and it would return 2, we hope!
There is another command line argument that sets enviroment variables, but that is only used by the real geeks and hackers. C Language help Argc is the number of arguments. The difference between the two versions is simply if you want to parse command line arguments or not - if you are not interested in them then you can ignore them using the second form. Asked 6 Months ago Answers: 5 Viewed 69 times.
What does this mean, and is it vital to my program? They are modifiable. That means they are not string literals. Only authorized users can answer the question. Please sign in first, or register a free account. Thought I should add, this is the same in most systems out there, although they're abstracted some times.
Show 6 more comments. Peter Mortensen 29k 21 21 gold badges 97 97 silver badges bronze badges. John Boker John Boker Add a comment. Two additional things to note: These are the only two standard-mandated signatures for main.
If a particular platform accepts extra arguments or a different return type, then that's an extension and should not be relied upon in a portable program. Toby Speight Toby Speight If we're being technical, basic. So, they're not exactly non-conforming. Thanks for the nice pedantry Justin.
Answer updated to be more correct. Azeem 7, 4 4 gold badges 20 20 silver badges 34 34 bronze badges. Argv[] always has argv[arg] as a null pointer. In the case of Bash, it is often maybe always the pathname of the executable, but Bash is not the only program that executes other programs. It cannot take any command line arguments. When run like such: myprogram arg1 arg2 arg3 argc , or Argument Count, will be set to 4 four arguments , and argv , or Argument Vectors, will be populated with string pointers to "myprogram", "arg1", "arg2", and "arg3".
Nick Gerakines Nick Gerakines 1, 1 1 gold badge 11 11 silver badges 20 20 bronze badges. Community Bot 1 1 1 silver badge. Chris Becke Chris Becke Might want to put void in I don't know if all older versions of C allow void functions to have an empty parameter list in declaration. Only in C this does have a difference, but only in declarations, not in definition. Ruslan Sorry, I posted this when I was just learning C, and I might have read that in very early versions of C the void is required.
Don't quote me on that, and I now know it is a slightly foolish comment.
0コメント