Sample Video Frame

Created by Zed A. Shaw Updated 2024-02-17 04:54:36

Exercise 5: Memorizing C Operators

When you learned your first programming language, it most likely involved going through a book, typing in code you didn't quite understand, and then trying to figure out how it worked. That's how I wrote most of my other books, and that works very well for beginners. In the beginning, there are complex topics you need to understand before you can grasp what all the symbols and words mean, so it's an easy way to learn.

However, once you already know one programming language, this method of fumbling around learning the syntax by osmosis isn't the most efficient way to learn a language. It works, but there is a much faster way to build both your skills in a language and your confidence in using it. This method of learning a programming language might seem like magic, but you'll have to trust me that it works surprisingly well.

How I want you to learn C is to first memorize all the basic symbols and syntax, then apply them through a series of exercises. This method is very similar to how you might learn human languages by memorizing words and grammar, and then applying what you memorize in conversations. With just a simple amount of memorization effort in the beginning, you can gain foundational knowledge and have an easier time reading and writing C code.

WARNING: Some people are dead against memorization. Usually, they claim it makes you uncreative and boring. I'm proof that memorizing things doesn't make you uncreative and boring. I paint, play and build guitars, sing, code, write books, and I memorize lots of things. This belief is entirely unfounded and detrimental to efficient learning. Please ignore anyone telling you this.

How to Memorize

The best way to memorize something is a fairly simple process:

There are many other tricks to memorizing things, but I've found that this is the best way to build instant recall on things you need to be able to use immediately. The symbols, keywords, and syntax of C are things you need instant recall on, so this method is the best for this task.

Also remember that you need to do both sides of the cards. You should be able to read the description and know what symbol matches it, as well as the description for a symbol.

Finally, you don't have to stop while you're memorizing these operators. The best approach is to combine this with exercises in this book so you can apply what you've memorized. See the next exercise for more on this.

The List of Operators

The first operators are the arithmetic operators, which are very similar to almost every other programming language. When you write the cards, the description side should say that it's an arithmetic operator, and what it does.

Arithmetic OperatorDescription
+Add
-Subtract
*Multiply
/Divide
%Modulus
++Increment
--Decrement

Relational operators test values for equality, and again they are very common in programming languages.

Relational OperatorDescription
==Equal
!=Not equal
>Greater than
<Less than
>=Greater than equal
<=Less than equal

Logical operators perform logic tests, and you should already know what these do. The only odd one is the logical ternary, which you'll learn later in the book.

Logical OperatorDescription
&&Logical and
||Logical or
!Logical not
? :Logical ternary

Bitwise operators do something you likely won't experience often in modern code. They alter the bits that make up bytes and other data types in various ways. I won't cover this in my book, but they are very handy when working with certain types of lower level systems.

Bitwise OperatorDescription
&Bitwise and
|Bitwise or
^Bitwise xor
~Bitwise ones compliment
<<Bitwise shift left
>>Bitwise shift right

Assignment operators simply assign expressions to variables, but C combines a large number of other operators with assignment. So when I say and-equal, I mean the bitwise operators, not the logical operators.

Assignment OperatorDescription
=Assign equal
+=Assign plus-equal
-=Assign minus-equal
*=Assign multiply-equal
/=Assign divide-equal
%=Assign modulus-equal
<<=Assign shift-left-equal
>>=Assign shift-right-equal
&=Assign and-equal
^=Assign xor-equal
|=Assign or-equal

I'm calling these data operators but they really deal with aspects of pointers, member access, and various elements of data structures in C.

Data OperatorDescription
sizeof()Get the size of
[]Array subscript
&The address of
*The value of
->Structure dereference
.Structure reference

Finally, there are a few miscellaneous symbols that are either frequently used for different roles (like ,), or don't fit into any of the previous categories for various reasons.

Misc. OperatorDescription
,Comma
( )Parenthesis
{ }Braces
:Colon
//Single-line comment start
/*Multi-line comment start
*/Multi-line comment end

Study your flashcards while you continue with the book. If you spent 15-30 minutes a day before studying, and another 15-30 minutes before bed, then you could most likely memorize all of these in a few weeks.

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.