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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:58:30+00:00 2026-06-01T20:58:30+00:00

The question is to describe what the code does, what the function does. The

  • 0

The question is to describe what the code does, what the function does.

The following code is part of the past exam papers for a 2nd year C and C++ module. The task is to describe what the following piece of code does. I’ve written the code exactly as presented, with some comments added by myself.

int g(int * y, unsigned size, int z) {
    int tmp = y[0];
    // what type is unsigned size? Int I presume. Why would you add an int to an array of ints?
    int * b = y + size; 
    y[0] = z;
    // I have the most difficulty understanding the following.
    while (1) if (*(--b)==z){y[0] = tmp; return b - y;};
    // are the following 3 lines ever even reached?
    y[0] = tmp;
    if (tmp == z) return 0;
    else return -1;
}
  • 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-01T20:58:31+00:00Added an answer on June 1, 2026 at 8:58 pm
    // what type is unsigned size?
    

    It’s an unsigned int called size. You add it to a pointer as in normal pointer arithmetic – advance this pointer to the very end of the array.

    while (1) if (*(--b)==z){y[0] = tmp; return b - y;};
    

    OK, we’ve got

    • while(1) = while(true), or ‘loop forever’
    • *(--b) pre-decrement b and read the value from that index of the array
    • if we’ve found z, replace the first element with the value we read from it and return b-y – pointer arithmetic for the array index we’re at

    i.e. we’re scanning backwards through the array to find the last instance of z and returning the index at which we found it. We will always find z in the array because we put it there as the first element, i.e. if z isn’t in the array then we return 0.

    // are the following 3 lines ever even reached?
    

    No, I don’t think so.

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

Sidebar

Related Questions

I am using the code as described in this question. However get following error
I encountered the following interview question on the Internet. Describe a data structure for
[Apologies if my question title does not accurately describe my problem- if you can
The question is probably not the best one to describe my issue but I
Struggled to adequately describe the scenario in the question. I'm trying to learn jQuery
Thanks for viewing my question. Let me describe the app first. I have a
That's it. My question is aboe in the title. I'll try to describe the
I'm not sure how to describe this, but I'll try with some basic code:
Hello everyone I have a question that I will describe as good as I
While searching for an answer to this question I found this sample code which

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.