Why is the following program legal, but not the one beneath it? I'm adding the values of two pointers which works if I point them to an existing variable but it does not work if I initilize the pointer to a value.
LEGAL
int main()
{
int i = 3;
int j = 5;
int *x = &i;
int *y = &j;
int z = (int)*x+*y;
printf("%d\n", z);
return 0;
}
ILLEGAL - SEGMANTATION FAULT
int main()
{
int *x = (int *)3;
int *y = (int *)5;
int z = (int)*x+*y;
printf("%d\n", z);
return 0;
}