Doubt when using variables

Asked

Viewed 53 times

0

#include <stdio.h>

main()
{
    float valor;

    printf("...");
    scanf("%f", &valor);
    printf("%0.2f", valor);
}

In scanf I must refer to the pointer (memory space), already in printf this reference is not valid. What is the most coherent explanation?

  • C has no reference.

  • 1

    When you pass valor at the printf, you are passing the contents of the variable (which is exactly what this function needs, since its task is to print this value). Already for the function scanf It would be useless to pass a value, what it needs is a place to store the value that the user informs. It needs a memory address to do this, so it gets a pointer. That’s because in C the arguments are always passed by value.

  • Doubt clarified. Thank you. Finally, in C, this symbol has some special name?

  • That operator & is called "address-of".

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.