diff --git a/blog/posts/basics-c-pointers/TRANSCRIPT.md b/blog/posts/basics-c-pointers/TRANSCRIPT.md index 81c459b..bc71f53 100644 --- a/blog/posts/basics-c-pointers/TRANSCRIPT.md +++ b/blog/posts/basics-c-pointers/TRANSCRIPT.md @@ -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? ------------------------------------------- diff --git a/blog/posts/basics-c-pointers/ex1.c b/blog/posts/basics-c-pointers/ex1.c new file mode 100644 index 0000000..9229e63 --- /dev/null +++ b/blog/posts/basics-c-pointers/ex1.c @@ -0,0 +1,9 @@ +#include +#include + +int main(){ + int *p; + //*p = 10; + printf("The value is: %ld\n", sizeof(*p)); + return 0; +}