C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1

integer sizes. Notice that the character array size is 12, which includes the null zero.


Tip

The length of a string and the size of a string are two different values. The length is the
number of bytes up to but not including the null zero, and it is found via strlen().
The size of a string is the number of characters it takes to hold the string, including the
null zero.

Note

Although sizeof() might seem worthless right now, you’ll see how it comes in
handy as you progress in C.

The Absolute Minimum
The goal of this chapter was to round out your knowledge of C operators.
Understanding these operators doesn’t take a lot of work, yet the operators are
powerful and substitute for complete statements in other languages. Key concepts from
this chapter include:


  • Use the conditional operator in place of simple if...else statements to improve
    efficiency.

  • The conditional operator requires three arguments. Extra parentheses help clarify
    these three arguments by separating them from each other.

  • Use ++ and -- to increment and decrement variables instead of adding and
    subtracting 1 using assignment or the += and -= operators.

  • Don’t think that a prefix and postfix always produce the same values. A prefix and
    postfix are identical only when a single variable is involved. If you combine ++ or
    -- with other variables and expressions, the placement of the prefix and postfix is
    critical to get the result you want.

Free download pdf