print a variable int in C

Asked

Viewed 68 times

-3

I’m in need of some help.

want to print the value of an int variable decided by scanf, but when I compile and run the program it returns me the following value:

"type the value of A -->11

the entered value was: 6422300"

my code:

    #include <stdio.h>

int main()
{
    int a;

    printf("digite o valor de A --->");
    scanf("%d", &a);
    printf("\n o valor digitado foi: %d", &a);



    return 0;
}

thank you in advance

3 answers

1

This happens because you are trying to print &a, which is the memory address of the variable a. To print what you want, as in the following example, remove the &:

printf("Variável: %d", a);

1

You need to take out the signal & (ampersand) of the second printf of your code.

The right thing would be printf("\n o valor digitado foi: %d", a);

1

When printing the variable, do not use the &, only the variable you want to print; the correct would be: printf("o valor digitado foi:%d",a);

Browser other questions tagged

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