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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:12:56+00:00 2026-06-02T16:12:56+00:00

How does the second argument of strtol work? Here is what I tried: strtol(str,

  • 0

How does the second argument of strtol work?

Here is what I tried:

strtol(str, &ptr, 10)

where ptr is a char * and str is a string. Now, If I pass in str as '34EF', and print *ptr, it correctly gives me E, and *(ptr+1) gives me F, however if I print ptr, it gives me EF! Shouldn’t printing ptr just result in a rubbish value like a hex address or something?

  • 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-02T16:12:58+00:00Added an answer on June 2, 2026 at 4:12 pm

    ptr is a pointer to the interior of a null terminated string. So given "34EF" it ends up pointing to the character 'E' and the string starting at that address is "EF".

    A four-character C string like p = "34EF" actually contains five strings in one. The string p is "34EF". The string p+1 is "4EF"; the string p+2 is "EF"; p+3 is "F" and p+4 is the empty string "". In this case p+4 points to the null terminator byte after the F.

    Speaking of the empty string, if the input to strtol consists only of valid characters making up the numeric token, then ptr should point to an empty string.

    If you want to disallow trailing junk, you can test for this. That is, even if a valid number parses out, if *ptr is not 0, then the input has trailing junk. In some cases, it is good to reject that: “Dear user, 10Zdf is not a number; please enter a number!”

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

Sidebar

Related Questions

Why does memset take an int as the second argument instead of a char
The ff. does not work. Second line is rendered on the same line as
How does the anonymous callback function know that 'item' (or really the second argument
In function _beginthread , what does the second argument (stack_size) mean? Stack size of
What does the second line inside this for loop means and what will be
When using a computational expression, the first definition works but the second does not
I am working in two java projects. The first supports OSGi components, second does
DTF does not call the second action if the custom action assembly has more
Why does the following code throw an exception when getting to the second scanf_s
Once you learn one language does it become easier to learn a second and

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.