Test your understanding of null termination, strlen vs sizeof, strcmp, and string assignment.
char s[] = "Hello"; printf("%lu\n", sizeof(s));
'\0' (null terminator) appended.char s[] = "ABC"; printf("strlen=%lu, sizeof=%lu\n", strlen(s), sizeof(s));
strlen returns the number of characters excluding '\0' → 3. sizeof returns the size in bytes including '\0' → 4.char a[] = "apple"; char b[] = "apple"; if (strcmp(a, b) == 0) { printf("same\n"); } else { printf("different\n"); }
strcmp returns 0 when the two strings are equal.== directly would compare addresses, not contents, so always use strcmp for string comparison in C.char s[10]; s = "Hello"; printf("%s\n", s);
=. Use strcpy(s, "Hello") instead.char s[] = "Hello" at declaration time is initialization, which is allowed. Initialization and assignment are different.