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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:44:05+00:00 2026-05-16T07:44:05+00:00

How does this code concatenate the data from the string buffer? What is the

  • 0

How does this code concatenate the data from the string buffer? What is the * 10 doing? I know that by subtracting ‘0’ you are subtracting the ASCII so turn into an integer.

char *buf; // assume that buf is assigned a value such as 01234567891234567
long key_num = 0;
someFunction(&key_num);
...

void someFunction(long *key_num) {

    for (int i = 0; i < 18; i++)
        *key_num = *key_num * 10 + (buf[i] - '0')
}

(Copied from my memory of code that I am working on recently)

  • 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-16T07:44:06+00:00Added an answer on May 16, 2026 at 7:44 am

    It’s basically an atoi-type (or atol-type) function for creating an integral value from a string. Consider the string "123".

    Before starting, key_num is set to zero.

    • On the first iteration, that’s multiplied by 10 to give you 0, then it has the character value '1' added and '0' subtracted, effectively adding 1 to give 1.
    • On the second iteration, that’s multiplied by 10 to give you 10, then it has the character value '2' added and '0' subtracted, effectively adding 2 to give 12.
    • On the third iteration, that’s multiplied by 10 to give you 120, then it has the character value '3' added and '0' subtracted, effectively adding 3 to give 123.

    Voila! There you have it, 123.

    If you change the code to look like:

    #include <iostream>
    
    char buf[] = "012345678901234567";
    void someFunction(long long *key_num) {
        std::cout << *key_num << std::endl;
        for (int i = 0; i < 18; i++) {
            *key_num = *key_num * 10 + (buf[i] - '0');
            std::cout << *key_num << std::endl;
        }
    }
    
    int main (void) {
        long long x = 0;
        someFunction (&x);
        return 0;
    }
    

    then you should see it in action (I had to change your value from the 17-character array you provided in your comment to an 18-character one, otherwise you’d get some problems when you tried to use the character beyond the end; I also had to change to a long long because my longs weren’t big enough):

    0
    0
    1
    12
    123
    1234
    12345
    123456
    1234567
    12345678
    123456789
    1234567890
    12345678901
    123456789012
    1234567890123
    12345678901234
    123456789012345
    1234567890123456
    12345678901234567
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Internet Explorer 7 doesn't do so well, but IE8 does.… May 16, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer You've omitted the ] from the list slice. But what… May 16, 2026 at 2:42 pm
  • Editorial Team
    Editorial Team added an answer You can use .wrapInner() and the <a> itself to do… May 16, 2026 at 2:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Question from the one interview. Please explain what does this C++ code mean: void
What does this error mean? TypeError: cannot concatenate 'str' and 'list' objects Here's part
Why does this code not work? echo explode(?, $_SERVER[REQUEST_URI])[0]; It says syntax error, unexpected
I can't understand why does this code fail with segfault: #include <cstdlib> #include <iostream>
Possible Duplicate: or is not valid C++ : why does this code compile ?
my target is it to collect data from clients which send data to an
One of the C++0x improvements that will allow to write more efficient C++ code
Say I have a class Code defined like this, with a user specified type
I have the following code that responds to a button click, changes the view
Here's my code: // Not all headers are relevant to the code snippet. #include

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.