Data Types
Integer
int is typically 4 bytes.
_t
is types that are designed to be cross-platform compatible, which means they include the given number of bytes no matter what system they run on.
You can specify any byte size to int using:
You don't have to specify the u = unsigned, it's commonly used to represent the values that are non-negative which saves memory space.
Boolean
Boolean data type for storing 0 or 1 values.
Used for on/off, yes/no, true/false situation (binary choices).
Include <stdbool.h> to use bool instead of _Bool.
size_t
size_t → Used to represent the size of objects in bytes and is therefore used as the return type by the sizeof operator.
size_t is a type guaranteed to hold any array index only for non-negative values.
wchar_t
wchar_t → Wide char is similar to char data type, except that wide char take up twice the space and can take on much larger values as a result.
Char can take 256 values which corresponds to entries in the ASCII table.
On the other hand, wide char can take on 65536 values which corresponds to UNICODE values which is a recent international standard which allows for the encoding of characters for virtually all languages and commonly used symbols.
Example:
char
Represents a single character such as the letter 'a'.
Char always uses single quotes.
char grade = 65; → is valid for ASCII code but not recommended.
Escape Characters
Data Type Conversion Functions
Printing Format Strings
Typedef
A keyword that allows us to create our own name for an existing data type.
Defines the name counter to be equal to the C data type int.
Now variables can be declared of type counter:
Operators
Example:
Difference between x++ and ++x
++x happens prior to assignment (per-increment).
x++ happens after assignment (post-increment).
x++ executes the statement and then increments the value.
++x increments the value and then executes the statement.
Logical Operators
&& → AND operator, if both are non-zero the condition is true (A && B) is false.
|| → OR operator, if any or both are non-zero the condition is true (A || B) is true.
! → NOT operator, reverse the logical statement !(A && B) is true.
Last updated