Skip to content

Instantly share code, notes, and snippets.

@mie00
Created April 8, 2014 09:19
Show Gist options
  • Save mie00/10103814 to your computer and use it in GitHub Desktop.
Save mie00/10103814 to your computer and use it in GitHub Desktop.
Dosoky c
#include <stdio.h>
void change(int* xp){ //define "declare" pointer called xp , type "int*" NOT "int"
printf("0:%d\n",*xp); //print x - the value which pointer points to - old value
*xp=6; // change the value of x - using its addr -
printf("1:%d\n",*xp); //print x - the value which pointer points to - new value
printf("5:%p\n",xp); // print the pointer " the addr of var. x"
printf("2:%p\n",&xp); //print the addr of the pointer xp
}
int main(){
int x=5;
printf("4:%p\n",&x); //print the addr of int x " x pointer"
change(&x); // send the addr of int x to change fn
printf("3:%d\n",x); //print the value of int x - the new value-
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment