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:

ex12.c

 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.