Why did I ever embarrass myself by explaining to a colleague
char a [100]; Scan ("% s", & amp; A); // Notices & amp;
in front of 'A' is very bad and there is a little better way to do this:
char a [100]; Scan ("% s", A); // Notices & amp; In front of 'A',
Ok everyone is getting ready to tell me why the scans should not be used for security reasons? This question is actually about the meaning of "& a" versus "a".
That's it, I have explained why it should not work, we tried to do it (with GCC) and it works =)). I ran a quick
printf ("% p% p", a, & a);
And it prints the same address twice.
Can anyone tell me what is happening?
OK, and
should be clear case. You know the array, as expected A
is a bit more subtle, but the answer is that is a
is array and as any other programmer knows, arrays are slightly There is also a tendency to change on the stimulus as an indicator, for example example while rendering it as a function parameter.
then course Edit: It seems that I've failed to fully consider the argument type scanf is actually expected in both cases An indicator is generated at the same address, but different types of (Letter to character for pointer, array of characters versus versus) And I will gladly accept that I do not have enough information about semantics for the elipassis (...), which I have always left the plague, it seems that any kind of infection To change, behavior like behavior can be unchanged behavior. Read the comments, and respond to LitBab. You can usually trust him so that these things are right. ;) scanf
scanf ("% s", a)
expects an indicator, not array, so array array The first element of this is changed into an indicator.
Comments
Post a Comment