mohannadalnono
mohannadalnono

Reputation: 115

Playing with pointer in c language

Could we point and address specific place in memory using pointer in c language? Then modify it from another file (ANOTHER PROGRAM) and view it from any where. Like :

Modifying it :

#include<stdio.h>

void main(){


   int *p;
   p= 12345678;
   scanf("%d",p);

}

Viewing it :

#include<stdio.h>

void main(){


   int *p;
   p= 12345678;
   printf("%d", *p);

}

Upvotes: 0

Views: 122

Answers (2)

Patryk Gawroński
Patryk Gawroński

Reputation: 185

What about const volatile pointer (which will be pointing to some memory)? If I'm not wrong it will point to some memory it won't change during first program (also you will not be allowed to modify this memory) but that memory can be modified by another program/process etc.

EDIT:

Just to clarify if we use const volatile pointer it will do two things.

  1. In program it won't allow us to change it value after initialisation
  2. More important volatile keyword will disallow some compiler optimisations on readings and will always reload from memory each time it is accessed by the program. This dramatically reduces the possible optimisations. However, when the state of an object can change unexpectedly, it is the only way to ensure predictable program performance.

Upvotes: 0

Jack Lilhammers
Jack Lilhammers

Reputation: 1247

No. Each process in your operating system has its own address space.
Processes can communicate, using the channels provided by the operating system.
Look into IPC, aka inter process communication, if you're interested in knowing more about it.

Upvotes: 1

Related Questions