As a result, the post this evening will be a combination of last nights studies and the knowledge I was able to retain this moments ago.
Last Night:
7.1 Introduction to Variables
7.2 Connections between functions return values and veriables
7.3 Terminating strings of text and other data
7.4 About printf and intro to placeholders
Some of the key things I took from last night:
How to tell a string in binary a string has stopped: 0000 0000 or Null terminated
%d and %i -- are placeholders for int
%u -- is a placeholder for unsigned int
%c -- character
%s -- string of text
%p -- memory address
Now, this evening got a little interesting but I will leave the excitement for the end of the blog. Ok, I'm sure it wont be exciting to anyone else, especially other programmers who have done this for awhile. Anyways, Section 8 was a pretty lengthy and time concerning lesson.
8.1 - Arrays and Pointers (Part 1)
8.2 - Arrays and Pointers (Part 2)
8.3 - Intro to Pointer Data Types
8.4 - How to Create a Pointer
8.5 - Assigning a Value to a Pointer
8.6 - Getting a Value Stored at a Memory Address
8.7 - Use what you've Learned
I'm not really quite sure how to explain everything I learned in Section 8. I guess I can really only show it.
I was able to write this code with out looking back at my notes and basing it all solely off of memory. Here is my first unassisted code:
#include <stdio.h> int main(void){ int total = 80; int *ptr = &total; printf("The total is %i \n", *ptr); printf("the memory address of %d is %p \n", *ptr, *ptr); int value = 20; int *myptr = &value; printf("The value is %i \n", *myptr); printf("the memory address of %i is %p \n", *myptr, *myptr); printf("Combined %d and %i equal %i \n",*ptr, *myptr, *ptr + *myptr); return 0; }
The link will take you directly to the program code and output.
http://codepad.org/TumHOBEc
No comments:
Post a Comment