in this code
printf("ingrese el numero a guardar");
scanf("%i",&a);
What is the function of aspersand(&) when saving the value and what is its name?
in this code
printf("ingrese el numero a guardar");
scanf("%i",&a);
What is the function of aspersand(&) when saving the value and what is its name?
Functions in
C
(most) start with a lowercase.The del function
scanf(tipo, &var);
must specify the type of data to read and the variable. in the types can be%i -> Integer , %s-> cadena , %f -> float , %c -> caracter
(the most common)The other parameter it receives is the variable, but first the
& ampersand
one that is used to indicate a memory address of the variable where the data will be stored appears.Why is it Omitted?
When a type variable is declared,
entero , flotante o char
it is assigned a memory address, how does itC
scanf
know in which address it will store the entered value? using the operator&
(by reference) , for an array or a String , the variable will also have the address of the first element, it is no longer necessary to pass the&
since it will know where to start writing the value orValores
First two clarifications:
printf
and not "Printf".scanf
and not "Scanf".The value you enter is actually being stored in the variable
a
, and in this case it must be an integer type, this is an example:Using the C language when we send values to a function it can be done in two ways:
In this case the ampersand (
&
) means indicating the memory address of the variable, sending the value by reference.