c - Why is the address operator (&) important for an array being passed through a function? -
i having trouble understanding how &
operator works , importance.
i found example online:
#include <stdio.h> void main() { int = 10; printf("\nvalue of n : %d" ,n); printf("\nvalue of &n : %u", &n); }
output :
value of n : 10 value of &n : 1002
firstly, why &n
print out 2 numbers?
secondly, why important?
n variable. represents value.
&n reference n. represents address in memory n store.
as why important:
when pass array in c, function expecting pointer. (ie: int* opposed int).
if pass 'n' function, complain when compiling because types don't match (n=int, function expects int*).
if pass in &n, passing in address 'n' function expects.
Comments
Post a Comment