I'm trying to swap two floats using pointers ,
My code :
#include <stdio.h>
void swap(float* p, float* q);
int main() {
double num1,num2;
printf("Please write 2 numbers ");
scanf("%lf %lf",&num1 , &num2);
swap(&num1,&num2);
printf("\nnum1 is : %.2lf \n",num1);
printf("num2 is : %.2lf \n",num2);
return 0;
}
void swap(float* p, float* q){
float a;
a=*p;
*p=*q;
*q=a;
}
My issues :
- The code doesn't swap
- The pointers in the swap function show value 0 for the pointer of the address I'm sending .
For example - input 99 22 -> gives me 0 :
I don't get why I'm getting that , if according to this comment I have an address that I sent (let's assume I sent 00001 ) then a pointer to that address would be my value (99 in this example ) but I get 0 ...
I'd appreciate any help !