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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:46:18+00:00 2026-06-05T09:46:18+00:00

I’m having a problem with pointers. Basically I have a struct which works as

  • 0

I’m having a problem with pointers. Basically I have a struct which works as a linked list queue Pcb below.

struct pcb {
    pid_t pid;             // system process ID
    char * args[MAXARGS];  // program name and args
    int arrivaltime;
    int remainingcputime;
    struct pcb * next;     // links for Pcb handlers
    int priority, memalloc, res1, res2, res3, res4, status;
};
typedef struct pcb Pcb;
typedef Pcb * PcbPtr;

Now you can see I’ve typedef’ed the Pcb pointer as PcbPtr, meaning that PcbPtr is a pointer right?
Then I implemented these functions to add a PcbPtr to the queue, depending on its priority:

PcbPtr enqPcb(PcbPtr headofQ, PcbPtr process){
    PcbPtr c = headofQ;
    if (!headofQ) {
        headofQ = process;
        return headofQ;
    }
    while (c->next) {
        c = c->next;
    }
    c->next = process;
    return headofQ;
}

void priEnq(PcbPtr f1, PcbPtr f2, PcbPtr f3, PcbPtr a) {
    int pri = a->priority;
    if (pri == 3)
        enqPcb(f3, a);
    else if(pri == 2)
        enqPcb(f2, a);
    else 
        enqPcb(f1, a);
    return;
}

but it’s not changing the object I’m pointing to (i.e. headf1 in this case:)

PcbPtr headi;
PcbPtr headf1; //priority 1
PcbPtr headf2; //priority 2
PcbPtr headf3; //priority 3
...
priEnq(headf1, headf2, headf3, headi);

so its as if I’m passing another object as the parameter. When I don’t use priEnq(), it adds to the list just fine.

Any ideas what I’m doing wrong? Any help is much appreciated

SOLVED:

PcbPtr enqPcb(PcbPtr *headofQ, PcbPtr process){
    PcbPtr c = *headofQ;
    PcbPtr d = c;
    if (!*headofQ) {
        *headofQ = process;
        return *headofQ;
    }
    while (c->next) {
        c = c->next;
    }
    c->next = process;
    return headofQ;
}

void priEnq(PcbPtr *f1, PcbPtr *f2, PcbPtr *f3, PcbPtr a) {
    int pri = a->priority;
    if (pri == 3)
        enqPcb(f3, a);
    else if(pri == 2)
        enqPcb(f2, a);
    else 
        enqPcb(f1, a);
    return;
}

PcbPtr headi;
PcbPtr headf1; //priority 1
PcbPtr headf2; //priority 2
PcbPtr headf3; //priority 3
...
priEnq(&headf1, &headf2, &headf3, headi);
  • 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-05T09:46:20+00:00Added an answer on June 5, 2026 at 9:46 am

    If I understand your problem correctly, the caller of priEnq has pointers to the queues, and wants those pointers updated if the function changes the head of the queue.

    The problem is that you’re passing the pointers by value. If you want the called function to modify the caller’s values, then you must pass by reference, ie, a pointer to the pointer you want updated. In code:

    PcbPtr enqPcb(PcbPtr *headofQ, PcbPtr process){
        PcbPtr* c = headofQ;
        if (!*headofQ) {
            *headofQ = process;
            return *headofQ;
        }
        while (c->next) {
            c = c->next;
        }
        c->next = process;
        return headofQ;
    }
    
    void priEnq(PcbPtr *f1, PcbPtr *f2, PcbPtr *f3, PcbPtr a) {
        int pri = a->priority;
        if (pri == 3)
            enqPcb(f3, a);
        else if(pri == 2)
            enqPcb(f2, a);
        else 
            enqPcb(f1, a);
        return;
    }
    
    PcbPtr headi;
    PcbPtr headf1; //priority 1
    PcbPtr headf2; //priority 2
    PcbPtr headf3; //priority 3
    ...
    priEnq(&headf1, &headf2, &headf3, headi);
    

    By passing the addresses of your queue pointers, you allow priEnq to modify your pointers, rather than just its own copies of them.

    Also, as sarnold mentioned, you might want to consider an array of queue pointers for readability and maintainability.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
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.

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.