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:

uint32_t // This is an int that holds 32 bytes (0 to 4294967295)
// or
int32_t // -2147483648 to 2147483647

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.

#include <stdbool.h>

bool var = true;
   
// Or we can do:

    _Bool y = 1; // True
    _Bool n = 0; // False


// Or use preprocessors (have to include stdbool header):

#define true 1
#define false 0

#define yes true
#define no false

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