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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:35:20+00:00 2026-06-13T21:35:20+00:00

I am looking at the following paragraph in the book Programming Interviews Exposed in

  • 0

I am looking at the following paragraph in the book “Programming Interviews Exposed” in reference to the implementation of a linked list stack in C:

typedef struct Element {
   struct Element *next;
   void *data; 
} Element;

void push( Element *stack, void *data ); 
void *pop( Element *stack );

Now consider what will happen in these routines in terms of proper
functionality and error handling. Both operations change the first
element of the list. The calling routine’s stack pointer must be
modified to reflect this change, but any change you make to the
pointer that is passed to these functions won’t be propagated back to
the calling routine. You can solve this problem by having both
routines take a pointer to a pointer to the stack. This way, you can
change the calling routine’s pointer so that it continues to point at
the first element of the list. Implementing this change results in the
following:

void push( Element **stack, void *data ); 
void *pop( Element **stack);

Could someone explain, in different words, why we need to use a double pointer here? I’m a bit unsure about the explanation provided.

  • 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-06-13T21:35:22+00:00Added an answer on June 13, 2026 at 9:35 pm

    It is similar to the famous swap() function in C.

    Case 1:

    void swapFails(int x, int y) {
        int temp = x;
        x = y;
        y = temp;
    }
    

    Case 2:

    void swapOk(int *x, int *y) {
        int temp = *x;
        *x = *y;
        *y = temp;
    }
    

    and we invoke swap like this:

    int x = 10;
    int y = 20;
    

    Case 1:

    swapFails(x, y);
    

    Case 2:

    swapOk(&x, &y);
    

    Remember, we wanted to CHANGE the values of x and y. For CHANGING values of a datatype, we need pointers. Take this to the next level for pointers. For CHANGING values of a pointer, we would need double pointers.

    For Stack using linked list:
    If you push values 10, 20 and 30, they are stored like this:

    top --- bottom
    30 -> 20 -> 10
    

    So you see every time you push or pop values from the stack, which is a linked list, the top or the first node of the linked list changes. Hence you need double pointers.

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

Sidebar

Related Questions

I'm looking at the following reference for making asynchronous web requests with C#: http://msdn.microsoft.com/en-us/library/86wf6409%28v=vs.100%29.aspx
I'm looking for the following solution in PHP. Whenever a user clicks on a
I was looking at the following code I came across for printing a string
I was looking at the following code in python: for ob in [ob for
I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
Trying to customize Symfony2 form to produce html code looking like the following example:
I come from ruby/C# and am new to Python. I'm looking at the following
Looking in this StackOverflow question it uses the following to send emails: System.Net.Mail.SmtpClient Is
Using the following query I am looking for a solution to get the latest
Im looking for a mobile SDK that has the following for iOS and Android

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.