VOID POINTER is not Fully Running

I think Every Declaration is correct but while running the control cannot print character and double datatype
This Program

#include <stdio.h>
 int main()
{
void *p;
int a;
scanf("%d",&a);
float d;
scanf("%f",&d);
char c;
scanf("%c",&c);
double f;
scanf("%lf",&f);
p = &a;
printf("\n%d",*(int*)p);
p = &d;
printf("\n%f",*(float*)p);
p = &c;
printf("\n%c",*(char *)p);
p = &f;
printf("\n%lf",*(double *)p);


return 0;
}

Help me with this…
If you run this then you can understand.

Working code,
Clear the input buffer before reading a character.

#include <stdio.h>
 int main()
{
void *p;
int a;
scanf("%d",&a);
float d;
scanf("%f",&d);

getchar();

char c;
scanf("%c",&c);

double f;
scanf("%lf",&f);
p = &a;
printf("\n%d",*(int*)p);
p = &d;
printf("\n%f",*(float*)p);
p = &c;
printf("\n%c",*(char*)p);
p = &f;
printf("\n%lf",*(double *)p);


return 0;
}
1 Like

Thank You My friend

1 Like

still compiler prints the output before i enter the input to double variable.

Solve this …

please share your output