Hello guys, consider the following code:
#include <stdio.h>
// Declare the function to swap two numbers
void swapping(int *num1, int *num2);
int main(void) {
int num1, num2;
// Get input from the user
printf("Enter num 1: \n");
scanf("%d", &num1);
printf("Enter num 2: \n");
scanf("%d", &num2);
// Call swapping function
swapping(&num1, &num2);
// Print the swapped values
printf("After swapping: num1 = %d, num2 = %d\n", num1, num2);
return 0;
}
// Define the swapping function
void swapping(int *num1, int *num2) {
int temp = *num1;
*num1 = *num2;
*num2 = temp;
}
consider this assignment :
*num1 = *num2
like here if num1 is pointing to memory address at 0x100 holding value 10 and pointer of num2 is pointing a memory address of 0x200 holding 20, this would mean 10 = 20
This doesn't make sense, right ? How should I interpret this statement then? Well, the thing is how can we think if it like a normal statement where we have something like "x = 35" for e.g