well ive been into the stack the last few days, hi!
here is an example i picked up from the web:
the important function i dont understand, or cant figure out, is the printf() call.Code:#include <stdio.h>
int main(int argc, char **argv)
{
char *somevar;
char *important;
char *temp;
somevar=(char *)malloc(sizeof(char)*4);
important=(char *)malloc(sizeof(char)*14);
strcpy(important, "command");
strcpy(somevar, argv[1]);
printf("%p\n%p\n", somevar, important);
printf("Starting To Print memory address:\n");
temp = somevar;
while(temp < important + 14)
{
/* this loop will be broken when we get to the last memory address we
want, last memory address of important variable */
printf("%p: %c (0x%x)\n", temp, *temp, *(unsigned int*)temp);
temp++;
}
return 0;
}
first off: we declared temp to be a pointer to type char.
so what is printf doing when called that way?
i could imagine that %p is the pointer address.(the memory location in the stack?)Code:printf("%p: %c (0x%x)\n", temp, *temp, *(unsigned int*)temp);
%c is used with *temp (a pointer to an array of type char?), what does that do?
and yes last but not least, there is that %x.
does %x print the hex values of the given variable? (without preceding "0x"?)
here are my questions listed: :D
1. i could imagine that %p is the pointer address.(the memory location in the stack?)
2.%c is used with *temp (a pointer to an array of type char?), what does that do?
3.does %x print the hex values of the given variable? (without preceding "0x"?)
thank you very much!!