I'm just learning C and was wondering which one of these I should use in my main method. Is there any difference?
Edit: So which one is more common to use?
I'm just learning C and was wondering which one of these I should use in my main method. Is there any difference?
Edit: So which one is more common to use?
I know this is outdated, but if you are just learning the C programming language and not doing anything major with it, don't use command-line options.
If you are not using command line arguments, don't use either. Just declare the main function as
int main()
If you-help
,/?
, or any other thing that goes afterprogram name
in terminal or command prompt)use whichever makes more sense to you. Otherwise, just use
int main()
After all, if you end up wanting to add command-line options, you can easily edit them in later.char ** → pointer to character pointer and char *argv [] means array of character pointers. As we can use pointer instead of an array, both can be used.
It doesn't really make a difference, but the latter is more readable. What you are given is an array of char pointers, like the second version says. It can be implicitly converted to a double char pointer like in the first version however.
If you'll need a varying or dynamic number of strings, char** might be easier to work with. If you're number of string is fixed though, char* var[] would be preferred.