Suppose I have the following code in my C program:
#include <stdio.h> void PrintSomeMessage( char *p ); int main(int argc, char *argv[]) { char arr[10] = "hello"; PrintSomeMessage(&arr[0]); return 0; } void PrintSomeMessage(char *p) { printf("p: %s",p); }
Why would the output of this be the whole word βhelloβ instead of a single βhβ character?
I understand, however, that if I put "%c" in the formatter, it will only print one letter. But still, the memory address for each letter in this address is different. Please, will someone explain this to me?
c arrays char printf
Nullpointerinterception
source share