Casting strings to integers and back
Can anyone explain why this is happening. First I will include the code that I am running.
Code:
#include <stdio.h>
int main(void)
{
char var1[4] = "FP10";
int var2 = 0;
printf("Value of var1 is %s\n", var1);
printf("Vaue of var2 is %d\n", var2);
memcpy(&var2, &var1, sizeof(var2));
printf("Vaue of var2 is %d\n", var2);
printf("String value of var2 is %s\n", &var2);
The output from this is:
Value of var1 is FP10
Value of var2 is 0
Value of var2 is 1179660592
String value of var2 is FP10FP10
Lines 1 and 2 are as you would expect, it is lines 3 and 4 that I did not get what i expected. I thought that the display of the value of var2 would show the ascii codes concatenated together and why is the string value displaying twice?
Thanks