July 2015
Intermediate to advanced
380 pages
10h 15m
English
This exercise shows you that C stores its strings simply as an array of bytes, terminated with the '\0' (nul) byte. You probably clued in to this in the last exercise since we did it manually. Here’s how we do it in another way to make it even clearer by comparing it to an array of numbers:
ex11.c
1 #include <stdio.h> 2 3 int main(int argc, char *argv[]) 4 { 5 int numbers[4] = { 0 }; 6 char name[4] = { 'a' }; 7 8 // first, print them out raw 9 printf("numbers: %d %d %d %d\n", 10 numbers[0], numbers[1], numbers[2], numbers[3]); 11 12 printf("name each: %c %c %c %c\n", 13 name[0], name[1], name[2], name[3]); 14 ...