Expressions become statements if you add a semicolon at the end of them (K&R C book)
Two things I found interesting and wrote down while reading the K&R C book (The C Programming Language by Ritchie & Kernighan), back in May 2024. I revisited again the note in 2026, and to be honest, I had forgot the 1st.
1. expressions vs statements
Expressions become statements if you add a semicolon at the end of them, K&R C book, Chapter 3.1, “Statements and Blocks”:
An expression such as
x = 0ori++orprintf(...)becomes a statement when it is followed by a semicolon, as in:
x = 0;
i++;
printf(...);In C, the semicolon is a statement terminator, rather than a separator as it is in languages like Pascal.
For more types of statements in C++ (we saw expression statements here), see https://en.cppreference.com/w/cpp/language/statements
2. braces
Also braces {} combine multiple statements into compound statements, which is another statement type.
Braces
{and}are used to group declarations and statements together into a compound statement, or block, so that they are syntactically equivalent to a single statement. The braces that surround the statements of a function are one obvious example; braces around multiple statements after anif,else,while, orforare another. (Variables can be declared inside any block; we will talk about this in Chapter 4.) There is no semicolon after the right brace that ends a block.
Other things to read
Popular
- Reveal animations on scroll with react-spring
- Gatsby background image example
- Extremely fast loading with Gatsby and self-hosted fonts