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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:33:12+00:00 2026-05-17T22:33:12+00:00

I have a char * that is actually 10 digit string. I basically take

  • 0

I have a char * that is actually 10 digit string. I basically take that in my function and spit out a code. Now i have made a static lib that i will share with someone else…the question is ( i am using c++)

for the definition of that api that i will provide in my header
do i just put const char * const or not. I am not sure if i need to do it or not. I just figured if they were going to use that API I did not want them to by mistake in their code send some bad pointer or value to my code. so to protect myself i am making it like i stated above is that the right approach? is that how one would use const?

  • 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-17T22:33:12+00:00Added an answer on May 17, 2026 at 10:33 pm

    Making something const does not mean that you won’t get a bad pointer. There’s nothing you can do to guard yourself against that. You can check for NULL, but not a freed pointer or a corrupted one.

    What const says is that your function promises not to change the data that is pointed to. That’s useful for the caller to know. Also, in cases where the caller only has access to const pointers, you are saving them a cast or copy to call your function.

    The normal usage is

     void makeCode(const char* s);
    

    Which means that the values pointed to by s won’t be changed.

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

Sidebar

Related Questions

I have recently made changes in some code that makes a char name field
I have code that looks something like, #include<stdlib.h> #include<string.h> char** someArray = NULL; size_t
We have a DB with a few hundred tables that have a CHAR Code
The cipher code actually works; it's just that I get some odd three digit
Okay, I actually don't have code as of yet because i'm just picking out
In C++ I have some code that requires a const char * to be
I have seen code that uses arrays of strings in the following way. string
In phpMyAdmin I have a char(32) column that has no default value(ie. Default: None).
I have extracted a MAC address into a char* array such that each section
I have a class User that looks like this: class User { private: char*

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.