Skip to content

Commit

Permalink
make more progress on c pointers transcript
Browse files Browse the repository at this point in the history
  • Loading branch information
joequery committed Jul 17, 2012
1 parent 2477075 commit d9ce4b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
36 changes: 34 additions & 2 deletions blog/posts/basics-c-pointers/TRANSCRIPT.md
Expand Up @@ -12,16 +12,48 @@ Things pointers make easy:

* Allowing a function to "modify a variable"
* Dynamic memory allocation
* Representation of data structures
* Representation of abstract structures

How do I declare a pointer?
How do I declare a pointer variable?
---------------------------

int x = 10;
int *p = &x;
printf("p is a memory address. See? %p\n", p);

-----

int x = 10;
int *p;
p = &x;
printf("p is a memory address. See? %p\n", p);

-----

int x = 10;
int *p = &x;

// %ld represents a long int for printf
printf("Size of a pointer to int: %ld\n", sizeof(p));
printf("Size of int: %ld\n", sizeof(*p));


What does it mean to 'dereference' a pointer?
---------------------------------------------

"Retrieve the value p is pointing at"
"The value associated with the memory address p"

int x = 10;
int *p = &x;
*p = 20;
printf("The value is: %d\n", *p);

// THIS IS WRONG
int *p;
*p = 10;


How do I handle pointers inside a function?
-------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions blog/posts/basics-c-pointers/ex1.c
@@ -0,0 +1,9 @@
#include<stdlib.h>
#include<stdio.h>

int main(){
int *p;
//*p = 10;
printf("The value is: %ld\n", sizeof(*p));
return 0;
}

0 comments on commit d9ce4b5

Please sign in to comment.