W
WD
I have a few questions regarding argv. When passing command-line
arguments to a C program, I understand that argc (int argc) is the
number of command-line arguments with which the program was invoked,
and argv (char *argv[]) is a pointer to an array of character strings
that contain the arguments, one per string. Why does the code
illustrated below work as written on i386 using Watcom C on Windows XP
and probably also using gcc on Linux as well?
#include <stdio.h>
main(x,y)
{
printf("%s\n",*(int *)y);
if (x>1)
{
y =y+4;
printf("%s\n",*(int *)y);
}
}
A few questions come to mind:
1.Does the compiler automatically assume main(x,y) to really mean
main(int x, char *y[]) ?
2.How does the first *(int *)y refer to y[0] (the first command-line
argument, i.e. the name of the program) ?
3.After y=y+4 why does the second *(int *)y now refer to y[1] (i.e.
the second command -line argument?
Thanks,
William
arguments to a C program, I understand that argc (int argc) is the
number of command-line arguments with which the program was invoked,
and argv (char *argv[]) is a pointer to an array of character strings
that contain the arguments, one per string. Why does the code
illustrated below work as written on i386 using Watcom C on Windows XP
and probably also using gcc on Linux as well?
#include <stdio.h>
main(x,y)
{
printf("%s\n",*(int *)y);
if (x>1)
{
y =y+4;
printf("%s\n",*(int *)y);
}
}
A few questions come to mind:
1.Does the compiler automatically assume main(x,y) to really mean
main(int x, char *y[]) ?
2.How does the first *(int *)y refer to y[0] (the first command-line
argument, i.e. the name of the program) ?
3.After y=y+4 why does the second *(int *)y now refer to y[1] (i.e.
the second command -line argument?
Thanks,
William