Memory - Week #4
Welcome back!
I’ve only got a short blog post today, as the course I’m currently taking is focusing mostly on theory and other computer science abstractions.
However, the most concrete of these topics is memory: specifically hexadecimals, addresses, and the syntax you need to know to implement these features in your code.
We first learned the decimal and character-counting system that computers use to understand values above 10, then 16, and so on.
0-9 is the first 10 digits, then 10-16 are represented in the letters A-F.
The specific context within which these concepts were presented was color, specifically how computers universally recognize different shades of RGB colors through their hex code. For instance, #0000FF is blue, because it is 100% B and 0% R(ed) or G(reen).
Addresses
Every shred of data stored on your computer has a particular address that can be reached by pointers, or at least in C. Misusing memory or having those chunks of information touch a bug, however, can actually be dangerous and potentially destabilize your code.
int n = 50;
I’ve just assigned the value of 50 to variable n.
int *p = &n;
Now, in this line of code, p is the address of an integer, in this case, the integer in question being n.
So, running this code…
#include <stdio.h>
int main(void)
{
int n = 50;
int *p = &n;
printf(“%p\n”, p);
}
…would return the address 0x7fff84f2ff0c.
Therefore, the code that I am running is storing the address of the integer n in p, and then printing the value of p so that I, in a sense, know where that information lives.
Fun quote: Programmers need to know that a piece of data exists, but you don’t need to be writing out the exact address each time you call it—you just need to know that the computer knows how to find it.
x—x
This was just a short section today—wish I could have written more code, but you have good days, and you have bad days. Looking forward to tomorrow.
Judson