0
l have a question about the pointer*
int a=1; int b=&a; or int a=1; int *b=&a; is it same?
3 Respostas
+ 3
alicia
No ,they are different.
●First:
int a=1;
int b=&a;
This will result in error. b is an integer variable not a pointer to int.
For assigning value to variables value must be compatible with type of variable.
As there is no conversation possible from `int *` to `int` it'll give a compile time error.
●Second
int a=1;
int *b=&a;
You are assigning address of `a` to a pointer variable `b`. This is valid. Also there is no need of type conversion/casting in this case.
+ 1
No,
int b is a normal integer variable which has value equal to memory address of variable a. But int *b is a pointer variable that store the value of a not the location.
If you print both b and *b then display some random integer(memory location) and 1 will show respectively.
In simple form you can say that * is used for accessing value stored at a particular memory location.
+ 1
Vijay Meena just adding, it's called dereferencing.