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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:25:44+00:00 2026-05-24T09:25:44+00:00

Hey so following this Question I’ve gotten stuck again, and yeah I’ve tried looking

  • 0

Hey so following this Question

I’ve gotten stuck again, and yeah I’ve tried looking through the web and through my textbook. I know its probably bad posting another question so soon, but I’m truly stumped on this problem. So anyways…

The next part of the assignment asks me to find the age of the person, this age is located on the next byte after the name. Basically if the name was “Bob” it would be

[L][u][k][e][\0][\0][1][5]

where all names with even number of characters get 2 null characters to make it even and then the next two bytes store a short integer. At the moment I have tried looking at the string length and then adding more onto the length before placing that onto the offset, but it doesnt seem to work

    if (name.length() % 2 != 0) {
        offset += (name.length());
        age = *((short*)foo+offset);
        cout << age << "\n";
    } else {
        offset += (name.length());
        age = *((short*)foo+offset);
        cout << age << "\n";
    }
  • 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-24T09:25:45+00:00Added an answer on May 24, 2026 at 9:25 am

    You are missing that C and C++ multiply pointer increments by the size of the object being pointed to. So *((short*)foo+offset) actually adds offset times sizeof(short) bytes to foo.

    Or maybe you understand this but don’t realise that a cast has a higher precedence than an addition, (short*)foo+offset is ((short*)foo)+offset not (short*)(foo+offset).

    Anyway what you want is *(short*)((char*)foo + offset). If foo is already a char* or some similar type, then you can omit the cast to char*.

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

Sidebar

Related Questions

Hey guys, I don't know if this question has been asked yet but imagine
Hey smarties. I'm having trouble with the following SQL statement. I know that I
hey, I am a newbie in symfony. I am following this joobet tutorial on
Hey all. Quick question on Fluent syntax. I had thought I had this down,
Hey I was following Michael Hartl's railstutorial when I stumbled upon this chunk of
Hey folks, sorry this is a bit of a longer question... I have a
Hey there, I have a probably straight-forward question about the following problem: I have
Hey dudes, I have the following function: $.fn.slideOut = function(speed,dir) { this.animate({ dir: '-1000px'
Hey i was in a local programming competition and they asked me this question
I'm absolutely sure this will be a trivial, newbie question, but hey - what's

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.