In an attempt to learn more about C, I have been playing with it for the past 2 days. I wanted to start watching how C is structured at run time, so I built a crappy program that asks the user for two integer values, and then prints the memory location of the integer variables. Then I want to check that the data is actually there, so I have a program suspended using getchar () to open GDB and save a segment of memory to validate the data, but the data in these places does not make much sense to me. Can someone explain what is going on here.
Program Code:
#include <stdio.h> void pause(); int main() { int a, b; printf("Please enter number one:"); scanf("%d", &a); printf("Please enter number two:"); scanf("%d", &b); printf("number one is %d, number two is %d\n", a, b); // find the memory location of vairables: printf("Address of 'a' %pn\n", &a); printf("Address of 'b' %pn\n", &b); pause(); } void pause() { printf("Please hit enter to continue...\n"); getchar(); getchar(); }
Output:
[ josh@TestBox c_code]$ ./memory Please enter number one:265 Please enter number two:875 number one is 265, number two is 875 Address of 'a' 0x7fff9851314cn Address of 'b' 0x7fff98513148n Please hit enter to continue...
GDB Hex dump memory segments:
(gdb) dump memory ~/dump2.hex 0x7fff98513148 0x7fff98513150 [ josh@TestBox ~]$ xxd dump2.hex 0000000: 6b03 0000 0901 0000 k.......
c gdb hexdump
Joshua faust
source share