0

diff between (int *)&a and &a

#include<stdio.h> int main() { int a; int *x; x = (int *) &a; //x=&a; above line and this are functioning same, so whats the difference a = 512; x[0] = 4; x[1] = 2; printf("%d",a); return 0; }

8th Mar 2020, 4:20 PM
Reiner
Reiner - avatar
4 ответов
+ 1
In C, `(type) expression` converts the expression to the specified type. For example 10 / 3 is 3 and 10 / (float) 3 is 3.333f. In this example &a is already of type (int *) so there is nothing for the conversion to do.
8th Mar 2020, 4:37 PM
Vlad Serbu
Vlad Serbu - avatar
0
if (char *) &a means integer to character conversion right
9th Mar 2020, 9:02 AM
Reiner
Reiner - avatar
0
Integer pointer to character pointer to be precise, but sure.
9th Mar 2020, 4:36 PM
Vlad Serbu
Vlad Serbu - avatar
0
Can you please explain with an example program
9th Mar 2020, 5:40 PM
Reiner
Reiner - avatar