Question: #include #include #include int main ( int argc, char * argv [ ] ) { int i = 0 ; int * p = malloc

#include
#include
#include
int main(int argc, char *argv[])
{
int i =0;
int *p = malloc(sizeof(int));
if (argc !=2){
printf("usage: mem
");
exit(1);
}
printf("(%d) addr pointed to by p: %p
",(int) getpid(), p);
*p = atoi(argv[1]);
for(i=0; i<5; i++){
sleep(1);
*p =*p +1;
printf("(%d) value of (*p): %d
",(int) getpid(),*p);
}
free(p);
return 0;
}
Compile and run it with the following command:
gcc vm.c && ./a.out 10
Let's say we get the following output:
(181980) addr pointed to by p: 0x405260
(181980) value of (*p): 11
(181980) value of (*p): 12
(181980) value of (*p): 13
(181980) value of (*p): 14
(181980) value of (*p): 15
Which section of the virtual memory space of this program/process is used to store the printed-out value "0x405260"?(Note that p is a local variable of integer pointer data type.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!