Pointers
These are variables that store the memory address of another variable, allowing direct access to and manipulation of data in memory.
Defining a Pointer
int value = 10;
int *ptr = &value; // ptr points to valueStructures
Structures or Structs are user-defined data types that allow the programmer to group related data items of different data types into a single unit. Structs can be used to store data related to a particular object. Structs help organize large amounts of related data in a way that can be easily accessed and manipulated.
Declaring a structure
typedef struct _STRUCTURE_NAME {
// structure elements
} STRUCTURE_NAME, *PSTRUCTURE_NAME;The STRUCTURE_NAME alias refers to the structure name, whereas PSTRUCTURE_NAME represents a pointer to that structure
Initializing a Structure
Initializing a structure will vary depending on whether one is initializing the actual structure type or a pointer to the structure. Continuing the previous example, initializing a structure is the same when using _STRUCTURE_NAME or STRUCTURE_NAME, as shown below.
STRUCTURE_NAME struct1 = { 0 }; // The '{ 0 }' part, is used to initialize all the elements of struct1 to zero
// OR
struct _STRUCTURE_NAME struct2 = { 0 }; // The '{ 0 }' part, is used to initialize all the elements of struct2 to zeroThis is different when initializing the structure pointer, PSTRUCTURE_NAME.
PSTRUCTURE_NAME structpointer = NULL;Initializing and Accessing Structures Members
A structure’s members can be initialized either directly through the structure or indirectly through a pointer to the structure. In the example below, the structure struct1 has two members, ID and Age, initialized directly via the dot operator (.).
typedef struct _STRUCTURE_NAME {
int ID;
int Age;
} STRUCTURE_NAME, *PSTRUCTURE_NAME;
STRUCTURE_NAME struct1 = { 0 }; // initialize all elements of struct1 to zero
struct1.ID = 1470; // initialize the ID element
struct1.Age = 34; // initialize the Age elementAnother way to initialize the members is using designated initializer syntax where one can specify which members of the structure to initialize.
typedef struct _STRUCTURE_NAME {
int ID;
int Age;
} STRUCTURE_NAME, *PSTRUCTURE_NAME;
STRUCTURE_NAME struct1 = { .ID = 1470, .Age = 34}; // initialize both the ID and the Age elementsOn the other hand, accessing and initializing a structure through its pointer is done via the arrow operator (->).
typedef struct _STRUCTURE_NAME {
int ID;
int Age;
} STRUCTURE_NAME, *PSTRUCTURE_NAME;
STRUCTURE_NAME struct1 = { .ID = 1470, .Age = 34};
PSTRUCTURE_NAME structpointer = &struct1; // structpointer is a pointer to the 'struct1' structure
// Updating the ID member
structpointer->ID = 8765;
printf("The structure's ID member is now : %d \n", structpointer->ID);The arrow operator can be converted into dot format. For example, structpointer->ID is equivalent to (*structpointer).ID. That is, structurepointer is de-referenced and then accessed directly.
Bitwise Operations
Right (>>) & Left Shift (<<):
There is right shift (>>) and left shift (<<). Right shifting can also be understood as dividing the number by multiple of two and left shift is multiplying by number by factor of two.
-
Left shift:

-
Right Shift:

Or (|):
Takes two binary values at bit level. It evaluates each bit of the first operand against the corresponding bit of the second operand. Getting a new Binary value as per the truth table follow.

AND (&):
Takes two binary values at bit level. It evaluates each bit of the first operand against the corresponding bit of the second operand. Getting a new Binary value as per the truth table follow.

XOR (^):
Takes two binary values at bit level. It evaluates each bit of the first operand against the corresponding bit of the second operand. Getting a new Binary value as per the truth table follow.

NOT (~):
Takes two binary values at bit level. It evaluates each bit of the first operand against the corresponding bit of the second operand. Getting a new Binary value as per the truth table follow.

Union:
In the C programming language, a Union is a data type that permits the storage of various data types in the same memory location. Unions provide an efficient way to use a single memory location for multiple purposes.
union Example {
int 123;
char aaa;
float 2.1;
}It’s important to note that in a union, assigning a new value to any member will change the value of all other members as well because they share the same memory location to store their data. Additionally, the memory allocated for a union is equal to the size of its largest member.
Enum Data Type
The Enum data type is used to define set of named consonants. To create an enumeration, the enum keyword is used.
enum example {
first_error, //0
second_error, //1
third_error, //2
forth_error, //3
fifth_error, //4
sixth_error, //5
}The compiler automatically assigns values to the constants, starting with 0 and increasing by 1 for each subsequent constant. It’s important to note that Enum lists cannot be modified or accessed using the dot (.) operator.
// Defining a "example" enum variable
enum example EnumName = third_error; // 2
// Check the value of "EnumName"
switch (EnumName){
case first_error:
printf("This Is one !\n");
break;
case second_error:
printf("This Is two !\n");
break;
case third_error:
printf("This Is three !\n");
break;
case forth_error:
printf("This Is four !\n");
break;
case fifth_error:
printf("This Is five !\n");
break;
case sixth_error:
printf("This Is six !\n");
break;
default:
break;
}Passing by Value
Passing by value is a method of passing arguments to a function where the argument is a copy of the object’s value.
int add(int a, int b)
{
int result = a + b;
return result;
}
int main()
{
int x = 5;
int y = 10;
int sum = add(x, y); // x and y are passed by value
return 0;
}Passing by Reference
Passing by reference is a method of passing arguments to a function where the argument is a pointer to the object, rather than a copy of the object’s value.
void add(int *a, int *b, int *result)
{
int A = *a; // A is now the same value of a passed in from the main function
int B = *b; // B is now the same value of b passed in from the main function
*result = B + A;
}
int main()
{
int x = 5;
int y = 10;
int sum = 0;
add(&x, &y, &sum);
// 'sum' now is 15
return 0;
}