I have to be aware of virtual address from the variables (the heap variable, particularly) during my project. The pointer worth of the variable is really its virtual address. My understanding would be that the Virtual Address of the identical variable if the same at different runs. I authored the next simple code to prove my ideas, however it works out to become wrong,

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
    int node=0;
    char* buffer;
    int i;
    printf("Hello World from Node %d the vm of i is %p and %ld \n",node, &i,&i);
    buffer = (char*)malloc(sizeof(char)*1024*1024*300); 
    for(i = 0; i < 1024*1024*300; i++){
    buffer[i] = (char)1;
printf("I  am in %d and the vm of buffer is %p:%ld \n",node, buffer,buffer);
return 0;

However I got different pointer values for various runs the following,

-bash-4.0$ gcc singletest.c
-bash-4.0$ ./a.out 
Hello World from Node 0 the vm of i is 0x7fffb87a8e00 and 140736288427520 
I  am in 0 and the vm of buffer is 0x7fb05dfcf010:140395467829264 
-bash-4.0$ ./a.out 
Hello World from Node 0 the vm of i is 0x7fffec2856f0 and 140737155454704 
I  am in 0 and the vm of buffer is 0x7f5888c54010:140018228477968 
-bash-4.0$ ./a.out 
Hello World from Node 0 the vm of i is 0x7fff1f44a780 and 140733717981056 
I  am in 0 and the vm of buffer is 0x7fbea3b91010:140456767328272 

I additionally authored an easy MPI code that every process simply creates the identical variable. And also the same variable for various processes possess the different pointer values, which isn't when i expected.

Can anyone explain this in my experience ? Thanks,

There is no guarantee that the variable's address would stay between runs. Modern os's attempt to alter the address programs are loaded into and also the heap and stack's addresses, exactly to avoid that from happening. Edge in the game since it causes it to be tougher for attackers to take advantage of certain classes of bugs.

Particularly, inside your situation, the variable you are searching at is really a pointer allotted around the heap. There's simply no reason to anticipate that allocating memory two times around the heap would make the same address two times.

This is comparable to among mine: Pseudo-random stack pointer under Linux?

It's all regulated accomplished for sercurity reasons, because the link within the awser describes.