Skip to content

Instantly share code, notes, and snippets.

@bhanubais
Created April 6, 2017 18:54
Show Gist options
  • Save bhanubais/5ef66cbe6691cc8c74f1eba56160b1f7 to your computer and use it in GitHub Desktop.
Save bhanubais/5ef66cbe6691cc8c74f1eba56160b1f7 to your computer and use it in GitHub Desktop.
C language pointer issue. Why I am getting 20 instead of 7 as a value of *nn in following code?
#include <stdio.h>
int *ptr(int n);
void nothing(int n1);
int main(void) {
int *nn = ptr(7);
nothing(20);
printf("*nn is %d\n", *nn); // why I am getting 20 instead of 7?
}
int *ptr(int n) {
int *p = &n;
printf("p is %d\n", *p);
return p;
}
void nothing(int n1) {
// int n2 = n1;
printf("n1 is %d\n", n1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment