Friday, January 29, 2016

Memory And Hex

As you may know I'm taking a class in C and C++ this semester (Spring of 2016) and have found C to be the best language ever (revised 2017: it's great and all, but not THIS great). It's really fun because of it's simplicity, the lack of functionality and user interface makes it easy and demanding of creativity. 

I just started reading up on pointers and memory addresses when I got curious about just how memory addresses are stored in pointers. Try compiling and running the simple function below to see how memory addresses are stored as hex values.


#include <stdio.h>
int main(){
int x, *p;
x =10;
*p = &x;
printf("value of x: %d", x);
printf("address of x: %p", &x);
printf("printout of pointer p: %p", p);
printf("value at p: %d", *p);
return 0;
}

No comments:

Post a Comment