Exercise 12. Sizes and Arrays

In the last exercise, you did math but with, a '\0' (nul) character. This may seem odd if you’re coming from other languages, since they try to treat strings and byte arrays as different beasts. C treats strings as just arrays of bytes, and it’s only the different printing functions that recognize a difference.

Before I can really explain the significance of this, I have to introduce a couple more concepts: sizeof and arrays. Here’s the code we’ll be talking about:


 1   #include <stdio.h>  2  3   int main(int argc, char *argv[])  4   {  5       int areas[] = { 10, 12, 13, 14, 20 };  6       char name[] = "Zed";  7       char full_name[] = {  8           'Z', 'e', 'd',  9            ...

Get Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.