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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:53:43+00:00 2026-06-09T03:53:43+00:00

I was reading though this: const char * const versus const char *? in

  • 0

I was reading though this: const char * const versus const char *?

in string.h, strlen is defined as:

size_t strlen ( const char * str );

If I understand this correctly, strlen expects a pointer to a char that is const. Shouldn’t it be:

size_t strlen ( const char* const str );

This would make sure that strlen cannot modify the pointer to point to a different pointer ?

Or, is this the case:

Since str pointer will be passed by value to strlen, any changes to this pointer in the function will not change the source pointer, and hence it’s okay..

??

  • 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-09T03:53:45+00:00Added an answer on June 9, 2026 at 3:53 am

    If you really read that discussion, you should understand that the second const has no effect on the external behavior of the function. For you, the user of strlen, It simply doesn’t make any difference whether it is declared with const char * or const char *const parameter. As you correctly noted, any modifications that strlen might do to the pointer are only affecting the internal, local copy of the pointer inside strlen. Your argument pointer that you pass to strlen will remain unchanged regardless of whether the parameter is declared with second const or not. (Your argument pointer doesn’t even have to be an lvalue.)

    The second const will only have effect on the internal behavior of the local parameter variable inside the function, preventing the authors of strlen from modifying that local variable. Whether they want to restrict themselves in that way or not is, informally speaking, their own business. It doesn’t concern the users of strlen in any way.

    In fact, since top-level const qualifiers have no effect on function type, it is typically possible to declare a function with const char * parameter and then define it with const char *const parameter. The compiler (linker) will still treat these declarations as “matching”. It means that if the library authors so desired, they could actually define strlen with const char *const parameter. They are simply not telling you about that, since this is effectively an implementation detail or strlen, i.e. something you don’t need to know.

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

Sidebar

Related Questions

I am currently reading though this tutorial here And in it he seems to
I'm currently reading through this jquery masking plugin to try and understand how it
I am reading STL source code right now. Though I understand the meat in
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
I have been reading through this wonderful website regarding the recommended Python IDEs and
I was reading through this thread: Hidden Features of JavaScript? and found this post:
I've been reading through regex and I thought this would work but it doesn't
Ok, I was reading through this entry in the FQA dealing about the issue
Can Any one help me reading this XML and Looping through <MedicationDispensed> I get

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.