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

  • Home
  • SEARCH
  • 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 8301827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:08:21+00:00 2026-06-08T17:08:21+00:00

Suppose I have a following linked list structure: struct linked_list { struct linked_list *next;

  • 0

Suppose I have a following linked list structure:

struct linked_list
{
    struct linked_list *next;
    int data;
};
typedef struct linked_list node;

And the following function to print the linked list:

void print(node *ptr)
{
    while(ptr!=NULL)
    {
        printf("%d ->",ptr->data);
        ptr=ptr->next;
    }
}

Now in the main() function when I write this:

print(head); // Assume head is the pointer pointing to the head of the list

This is essentially call-by-value. Because ptr in print will receive a copy of head. And we can’t modify head from the print() function because its call-by-value.

But my doubt is, since ptr receives a copy of head but it’s able to print the value of linked list. So does that means the print() function receives whole copy of linked list? If it does not receives the whole copy of linked list how its able to print the list?

  • 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-08T17:08:29+00:00Added an answer on June 8, 2026 at 5:08 pm

    print receives a copy of the address of head, which means that the data representing head isn’t copied: the function is using the actual head and hence the actual linked list, not a copy.

    The implications are that you can change head, e.g. head->data, and you can modify the rest of the linked list. The only thing that you can’t do is change which node your passed-in pointer points to, i.e. you can’t do head = NULL in print and expect that to be reflected outside print.

    So, any of the following changes are all reflected outside the function:

    // pick one:
    ptr->data = 20;
    ptr->next = NULL;
    ptr->next = malloc(sizeof(node));
    ptr->next->data = 20;
    // etc.
    

    The following aren’t:

    ptr = NULL;
    ptr = malloc(sizeof(node));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following simple struct: struct Vector3 { double x; double y;
Suppose I have the following list: ID3_tag = ['Title','Artist','Album','Track'] And I have a file
Suppose I have the following directory structure in Vim's NERDTree: /some/folder/ |-apples.txt |-bananas.txt |-
Suppose I have the following method signature int f (int[] values) and I call
I have the following function/constructor/method (I'm not sure exactly what it is) List<T>& List<T>::operator=(const
Suppose I have following data in my game. I have developed game in cocos2d.
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
Suppose I have following code def foo(x:Int):Unit = { if (x == 1) println
Suppose I have the following function, the value it produces is needed by many

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.