Created
April 6, 2017 18:54
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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