C++ Pointer Assignment Clarification -


what difference when have example,

int var1, *ptr; ptr = &var1; // pointer ptr copies address of var1, hence ptr points var1?  int var1, *ptr; ptr = var1; // ptr points var1, not have address of var1, can not change value of address var1?   int *var1, *ptr; *ptr = *var1; // copy value of var1 location pointed ptr? 

are comments correct ?

the second (ptr = var1) , third (*ptr = *var1) options wrong.

in second case, asking ptr point address written in var1. i.e. var1 integer value interpreted address. not want, , cause compiler error or warning.

in third case trying dereference not pointer (*var1). compiler error.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -