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 7616227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:50:25+00:00 2026-05-31T02:50:25+00:00

I’m learning C and now I hit a wall. Its difficult for me to

  • 0

I’m learning C and now I hit a wall. Its difficult for me to understand pointers.

Imagine I have this code:

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

#define DELTA 33

int calls, seed=356;

int sum_ds(int a){    
 int d=DELTA;          
 calls++;               
 return a+d+seed; 
}                       

int main() {
    int num;                                
    int *ptr;
    int **handle;

     num = 14;                              
     ptr = (int *)malloc(2 * sizeof(int));  
     handle = &ptr;
     *(*handle+0) = num;                    
     *(*handle+1) = num+1;  
     *ptr = num-2;      
     ptr = &num;        
     *ptr = sum_ds(num-2);
}

Lets go step by step trough my understanding.

1 – int calls creates a variable named calls and doesn’t initializes it so it contains rubbish. It is stored on DATA and let’s say with the memory address 0xFFAA.

2 – int seeds creates a variable named seeds initialized with the integer 356. It is stored on DATA and let’s say with the memory address 0xFFAB.

3 – int num creates a variable named num and doesn’t initializes it so it contains rubbish. It is stored on the STACK and let’s say with the memory address 0xFFAC.

4 – int *ptr creates a pointer to int and does not assign any address to it. It is stored on the STACK and let’s say with the memory address 0xFFAD.

5 – int **handle creates a pointer to a pointer of int and does not assign any address to it. It is stored on the STACK and let’s say with the memory address 0xFFAE. (MANY DOUBTS HERE)

6 – num = 14 goes to the address 0xFFAC and stores the number 14 on it. It’s done in the STACK.

7 – ptr = (int *)malloc(2 * sizeof(int)) On the HEAP it’s assigned memory size for 2 ints and the address of the first memory byte (let’s say 0xFFZZ) is stored (on STACK) on ptr so now *ptr points to that memory address.

8 – handle = &ptr handle now points to ptr. I believe it now points to whatever is on 0xFFZZ (MANY DOUBTS HERE)

9 – *(*handle+0) = num the pointer to the pointer of int now its assigned with the value of num (14) (MANY MANY MANY MANY DOUBTS HERE)

10 – *(*handle+1) = num+1 the pointer of pointer plus one of int now its assigned with the value of num + 1 (15) (MANY MANY MANY MANY DOUBTS HERE)

11 – *ptr = num-2 the value point by ptr it’s assigned with the value of num – 2 (12). I believe it goes to the memory address 0xFFZZ and stores there the number 12.

12 – ptr = &num ptr now points to num, i believe it now points to 0xFFAC.

13 – *ptr = sum_ds(num-2) the value pointed by ptr is the returned value of sum_ds. I belive 0xFFAC it’s assigned with 401 (12+33+356)

Is this right?

  • 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-31T02:50:26+00:00Added an answer on May 31, 2026 at 2:50 am

    1 – int calls creates a variable named calls and doesn’t initializes it so it contains rubbish. It is stored on DATA and let’s say with the memory address 0xFFAA.

    2 – int seeds creates a variable named seeds initialized with the integer 356. It is stored on DATA and let’s say with the memory address 0xFFAB.

    One little detail: sizeof(int) is greater than 1 (it is 4 on most mainstream platforms, so the 2nd address could not be 1 higher than the 1st. Other than that, AFAIK you are correct so far.

    3 – int num creates a variable named num and doesn’t initializes it so it contains rubbish. It is stored on the STACK and let’s say with the memory address 0xFFAC.

    4 – int *ptr creates a pointer to int and does not assign any address to it. It is stored on the STACK and let’s say with the memory address 0xFFAD.

    Another little detail: on most mainstream platforms, the stack grows downward, so the 4th address would be less than the 3rd. Other than that, AFAIK you are correct so far. (Moreover, addresses on the data segment, the heap and the stack would be rather different in real life.)

    7 – ptr = (int *)malloc(2 * sizeof(int)) On the HEAP it’s assigned memory size for 2 ints and the address of the first memory byte (let’s say 0xFFZZ) is stored (on STACK) on ptr so now *ptr points to that memory address.

    To be nitpicky, ‘Z’ is not a hexadecimal number 🙂 So let’s say it is 0x1000 instead.

    8 – handle = &ptr handle now points to ptr. I believe it now points to whatever is on 0xFFZZ (MANY DOUBTS HERE)

    No, handle now contains the address of ptr, that is 0xFFAD. Indirectly though – through ptr – it indeed points to 0x1000 (was 0xFFZZ in your example).

    9 – *(*handle+0) = num the pointer to the pointer of int now its assigned with the value of num (14) (MANY MANY MANY MANY DOUBTS HERE)

    Basically correct. The notation you use is not the easiest to deal with, which makes it more difficult for you to follow what’s going on. After step 8, *handle is equivalent to ptr. And due to pointers and arrays being interchangeable in many common situations, *(ptr+0) is equivalent to ptr[0], and also to *ptr.

    10 – *(*handle+1) = num+1 the pointer of pointer plus one of int now its assigned with the value of num + 1 (15) (MANY MANY MANY MANY DOUBTS HERE)

    Similar to the previous point, you are in effect assigning ptr[1] = num+1. Keep in mind though that ptr is int*, so the address difference between ptr and ptr + 1 equals to sizeof(int), which is, as mentioned above, usually 4.

    11 – *ptr = num-2 the value point by ptr it’s assigned with the value of num – 2 (12). I believe it goes to the memory address 0xFFZZ and stores there the number 12.

    Yes, this overwrites the value set in step 9.

    12 – ptr = &num ptr now points to num, i believe it now points to 0xFFAC.

    Correct.

    13 – *ptr = sum_ds(num-2) the value pointed by ptr is the returned value of sum_ds. I belive 0xFFAC it’s assigned with 401 (12+33+356)

    Correct. Since the previous step made *ptr equivalent to num, this call is also equivalent to num = sum_ds(num-2).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.