When I do this:
int main(int agrc, char argv)
{
printf("%d", argv);
return 0;
}
I get this input when I run the program from command line:
$ prog_name 0
0
$ prog_name (from 0-7 characters)
48
$ prog_name 12345678
56
$ prog_name 1234567812345678
64
// and so on...
So where do these values come from and why they increment by 8?
What happens when I have this instead:
int main(int agrc, char argv[])
?
From the C standards, regarding the signature of
main()
So, there will be no issues from the compiler if you pass different type of arguments.
In your code,
is not the signature recommended for
main()
. It should either beor, at least
Otherwise, in a hosted environment, the behavior in not defined. You can check more on this in
C11
standard, chapter 5.1.2.2.1.In your case, as you see, you are making the second parameter a
char
type. As per the standard specification,So, here, the supplied
0
is passed tomain()
as a pointer to string which is accepted in achar
, which is not a defined behavior.