Skip to content

Instantly share code, notes, and snippets.

@tedwardd
Created March 25, 2017 16:42
Show Gist options
  • Save tedwardd/1c200c68487f7ede93cc37fe89b75930 to your computer and use it in GitHub Desktop.
Save tedwardd/1c200c68487f7ede93cc37fe89b75930 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int *p;
p = (int*)malloc(sizeof(x));
p = &x;
scanf( "%d", &x );
printf( "%d\n", *p );
free(p);
}
@cdkersey
Copy link

I'd write what I think you're trying to do as:

int main()
{
  int *p = malloc(sizeof(int));

  scanf("%d", p);
  printf("%d\n", *p);

  free(p);

  return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment