On 20 Jan 2007 20:15:15 GMT, gabriel < XXXX@XXXXX.COM > wrote in
Of course you realize that your program will exhibit undefined
behavior if it is invoked with no command line arguments, because argv
 will be a null pointer.
For illustration purposes, let's assume that your program is invoked
with a single command line argument like this:
...so that argv will point to "abc".
x now points to the array of chars 'a', 'b', 'c', '\0', which can also
be referred to as the string "abc".
Here you pass argv, which is a pointer to character and points to
the string "abc" to printf() with a "%s" conversion specifier. Since
the argument matches "%s" and does point to a valid string, all is
Now y points to the string "abc".
Here you dereference y, to get what it points to. Since y is a
pointer to character, it points to a character, in this case the 'a'
Because of the "%s" conversion specifier, printf() is expecting a
pointer for the argument. You are passing it an int, containing the
numeric value of the character 'a'. printf() is trying to use that
numeric value as a pointer, and access a string of characters at that
But the numeric value of a char, converted to int, is not a pointer.
On some platforms, an int and a pointer to char are bit even the same
When you pass an argument type to printf() that does not match the
conversion specifier, the result is undefined behavior. On your
particular platform, the result of this undefined behavior is a
To make this work correctly, replace "*y" in the printf() call with
just plain 'y':
printf("*y = %s \n", y);
comp.lang.c.moderated - moderation address: XXXX@XXXXX.COM -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.