Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:55:21+00:00 2026-05-25T09:55:21+00:00

Here is my code int main() { pid_t pid; int y = 3; if

  • 0

Here is my code

int main()
{
  pid_t pid;
  int y = 3;  
  if ( (pid = fork()) <0 )
   return -1;;

  if( pid == 0 )  /* child */
  {
    printf(" before: %d %p\n", y, &y );
    y *= 10;
    printf("after: %d %p\n", y, &y );
  }
  else /* father */
  {
   sleep(1);
   printf("father: %d %p\n" , y , &y );

  }
  return 0;
}

The output of the program is like following:

before: 3 ffbff440
after: 30 ffbff440
father: 3 ffbff440

My question is why is address of variable of child and parent same but the value different?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:55:21+00:00Added an answer on May 25, 2026 at 9:55 am

    Because it’s a virtual address, not a physical one.

    Each process gets its own address space (for example, a 32-bit system may allow each process to have its own address space with the full 4G range).

    It’s the memory management unit that will map virtual addresses to physical ones (and handle things like page faults if swapped out pages need to be bought back in from secondary storage).

    The following diagram may help, each section representing a 4K block of memory:

       Process A           Physical Memory      Process B
       +-------+           +-------------+      +-------+
    0K |       |---->   0K |  (shared)   | <----|       | 0K
       +-------+           +-------------+      +-------+
    4K |       |--+     4K |             | <----|       | 4K
       +-------+  |        +-------------+      +-------+
    8K |       |  +->   8K |             |      |       | 8K
       +-------+           +-------------+      +-------+
           |                : : : : : : :           |
           |               +-------------+          |
           |          128K |             | <--------+
           |               +-------------+
           +--------> 132K |             |
                           +-------------+
    

    You can see, in that diagram, the disconnect between virtual memory addresses and physical memory addresses (and the possibility for processes to share memory blocks as well). The addresses down the left and right sides are virtual addresses which the processes see.

    The addresses in the central block are actual physical addresses where the data “really” is, and the MMU handles the mapping.

    For a deeper explanation of fork (and exec), you may also want to look at this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code int main(int argc,char *argv[]) { mysql_init(&mysql); connection = mysql_real_connect(&mysql,.............,3306,0); if
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
here is code #include <iostream> #include <map> using namespace std; int main(){ map<int ,int>a;
First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int
I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
here is my code for(int i = 0; i < number ; i++) {
here's the code: class Acount { int sum ; String owner ; //these seem
So here is my code: public MyClass (int y) { super(y,x,x); //some code }
const static int foo = 42; I saw this in some code here on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.