Jun 12, 2024
int a = 10;
int* p = &a; // Pointer p will store the address of a
*) is used to declare a pointer.&) gives the address of a variable.*p = 20; // The value of a will now be 20
p++;
p++ will point to the next memory location which is 4 bytes ahead.int arr[] = {10, 20, 30};
int* p = arr; // p is now pointing to the first element of arr
for(int i = 0; i < 3; i++)
printf("%d ", *(p + i));
int a = 10;
int* p = &a;
int** q = &p; // q is a pointer pointing to p
**q will access the value of a.void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x = 5, y = 10;
swap(&x, &y); // The values of x and y will swap
return 0;
}