0

& and * in C

I can't really understand when should i use & and * for a variable, i understand the concept but i cant use them when coding

15th May 2020, 11:32 AM
Guido Parlatore
Guido Parlatore - avatar
3 Respostas
+ 1
& -> get the address of an variable * -> declare a pointer / dereference a pointer A pointer is an variable that stores an address. Based on the definition above, the following statement is to declare a pointer initialized with an address: int* ptr = &an_variable; And this statement is to dereference the pointer: printf("%d", *ptr); which is equivalent to: printf("%d", an_variable);
15th May 2020, 11:51 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
They are generally used when you need to allocate memory at run-time. See Standard Template Library and Data Structures, these are one of the implementations of pointers.
15th May 2020, 12:15 PM
Mustafa K.
Mustafa K. - avatar