pointer does not work in visual studio

Asked

Viewed 52 times

1

Personal my question is simple but makes me unable to work with pointers, the variable 'y' simply does not receive the address of x in the example below:

#include<stdlib.h>
#include <locale.h>


int main()
{
    setlocale(LC_ALL, "portuguese");

    int *y, x;
    

    printf("Digite um numero: ");
    scanf_s("%d", &x);

    y = &x;

    printf("Voce digitou o numero %d\n", y);

    
    system("pause");
    return 0;
}

Thank you all for your help

  • 8

    Like y is a pointer you should use: printf("Voce digitou o numero %d\n", *y);. Print the content pointed by y.

  • That’s right, the literature I’m reading was incorrect at this point, at the time you print the contents of a pointer you need to type * before. Thanks!

  • 3

    If the literature you’re using is wrong at such a basic point I think it’s best to change literature.

1 answer

-2

places an asterisk before y in the printf("You have entered the number %d n", y);

Browser other questions tagged

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