Skip to content

Instantly share code, notes, and snippets.

@kybernetyk
Created January 13, 2011 11:52
Show Gist options
  • Save kybernetyk/777757 to your computer and use it in GitHub Desktop.
Save kybernetyk/777757 to your computer and use it in GitHub Desktop.
Everything is by value in C.
#include <stdio.h>
void foo (int *p)
{
printf ("\t1. p is pointing to: %p\n", p);
p = 0;
printf ("\t2. p is pointing to: %p\n", p);
}
int main (int argc, char **argv)
{
int my_stuff = 1234;
int *my_p = &my_stuff;
printf ("1. my_p is pointing to: %p\n", my_p);
foo (my_p);
printf ("2. my_p is pointing to: %p\n", my_p);
return 0;
}
@kybernetyk
Copy link
Author

Output on my machine is:

  1. my_p is pointing to: 0x7fff5fbff4bc
    1. p is pointing to: 0x7fff5fbff4bc
    2. p is pointing to: 0x0
  2. my_p is pointing to: 0x7fff5fbff4bc

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