Very new to C here and I think I just barely grasp the concept of pointers, but the syntax is a bit confusing so I'm having trouble trying to understand what this expression x = (char *) &a;
means.
Rest of function for reference:
#include<stdio.h>
int main()
{
int a;
char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
return 0;
}
More specifically, why is it necessary to write x = (char *) &a;
instead of just x = &a;
? What does the added (char *)
do to alter the expression?