What happens when you call printf() with argument-structure?

#include <stdio.h>
struct card 
{
 char * face;
 char * suit;
};
int main( void )
{
 struct card aCard = { "Three", "Hearts" }; 
 printf( "%s %s %s\n", aCard, aCard.face, aCard.suit );//Three Hearts Three
 printf( "%s\n", aCard );//Three; 
 printf( "%s\n", aCard.face );//Three; 
 printf( "%s\n", aCard.suit );//Hearts; 
}
April 3rd 20 at 18:24
1 answer
April 3rd 20 at 18:26
Solution
Because
printf("pattern", . . . , aCard, . . .);
equivalent
printf("pattern", . . . , aCard.face, aCard.suit . . .);

— The stack is placed on the structure of two pointers, i.e. just two pointers. The last argument (aCard.the suit in the first call to printf in question) is superfluous.

For example,
printf( "%s %s\n", aCard );
will give
Three Hearts
cool! - Sonya_Wiegand commented on April 3rd 20 at 18:29

Find more questions by tags C