I've seen in a site that int main(int argc, char* argv<::>)
can also be used as a signature of main
. Surprisingly, The following program:
int main(int argc, char* argv<::>)
{
return 0;
}
compiles withput any warnings in GCC , as well as clang. It also compiles in C++.
So, how is it that int main(int argc, char* argv<::>)
is a valid signature of main
?
Command-line Arguments: main( int argc, char *argv[] ) Here argc means argument count and argument vector. The first argument is the number of parameters passed plus one to include the name of the program that was executed to get those process running.
The first parameter, argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started. The second parameter, argv (argument vector), is an array of pointers to arrays of character objects.
The declaration char *argv[] is an array (of undetermined size) of pointers to char , in other words an array of strings. And all arrays decays to pointers, and so you can use an array as a pointer (just like you can use a pointer as an array).
What is ARGV? As a concept, ARGV is a convention in programming that goes back (at least) to the C language. It refers to the “argument vector,” which is basically a variable that contains the arguments passed to a program through the command line.
char* argv<::>
is equivalent to char* argv[]
. <:
and :>
used here are digraphs.
In all aspects of the language, the six tokens79)
<: :> <% %> %: %:%:
behave, respectively, the same as the six tokens
[ ] { } # ##
except for their spelling. 80)
Foot note:
79) These tokens are sometimes called ‘‘digraphs’’.
80) Thus [
and <:
behave differently when ‘‘stringized’’ (see 6.10.3.2), but can otherwise be freely interchanged.
An example:
%: define stringize(a) printf("Digraph \"%s\" retains its spelling in case of stringization.\n", %:a)
Calling the above macro
stringize( %:);
will print
Digraph "%:" retains its spelling in case of stringization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With