I am following the C primer plus and encounter the following example:
#include <stdio.h>
#include <string.h> //provide strlen() prototype
#define PRAISE "You are an extraordinary being with a big big brain."
int main(void)
{
char name[40];
printf("What's your name? ");
scanf("%s", name);
printf("Hello, %s. %s\n", name, PRAISE);
printf("Your name of %zd letters occupies %zd memory cells.\n", strlen(name), sizeof name);
printf("Size of the name %zd", sizeof(name));
return 0;
}
Compiled and run it:
$ ./a.out
What's your name? Trump
You are an extraordinary being with a big big brain."
Your name of 5 letters occupies 40 memory cells.
Size of the name 40
What puzzled me is that sizeof(name)
is identical to sizeof name
?
sizeof() is a library routine, but how abut sizeof, it seems as predicate and parameter as it was in command line.