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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:25:18+00:00 2026-05-20T12:25:18+00:00

This question may be naive, but: is there const keyword in C? since which

  • 0

This question may be naive, but:

  • is there const keyword in C?
  • since which version?
  • are there any semantic and/or syntactic differences between const in C and C++?
  • 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-20T12:25:19+00:00Added an answer on May 20, 2026 at 12:25 pm

    There are no syntactic differences between C and C++ with regard to const keyword, besides a rather obscure one: in C (since C99) you can declare function parameters as

    void foo(int a[const]);
    

    which is equivalent to

    void foo(int *const a);
    

    declaration. C++ does not support such syntax.

    Semantic differences exist as well. As @Ben Voigt already noted, in C const declarations do not produce constant expressions, i.e. in C you can’t use a const int object in a case label, as a bit-field width or as array size in a non-VLA array declaration (all this is possible in C++). Also, const objects have external linkage by default in C (internal linkage in C++).

    There’s at least one more semantic difference, which Ben did not mention. Const-correctness rules of C++ language support the following standard conversion

    int **pp = 0;
    const int *const *cpp = pp; // OK in C++
    
    int ***ppp = 0;
    int *const *const *cppp = ppp; // OK in C++
    

    These initializations are illegal in C.

    int **pp = 0;
    const int *const *cpp = pp; /* ERROR in C */
    
    int ***ppp = 0;
    int *const *const *cppp = ppp; /* ERROR in C */
    

    Generally, when dealing with multi-level pointers, C++ says that you can add const-qualification at any depth of indirection, as long as you also add const-qualification all the way to the top level.

    In C you can only add const-qualification to the type pointed by the top-level pointer, but no deeper.

    int **pp = 0;
    int *const *cpp = pp; /* OK in C */
    
    int ***ppp = 0;
    int **const *cppp = ppp; /* OK in C */
    

    Another manifestation of the same underlying general principle is the way const-correctness rules work with arrays in C and C++. In C++ you can do

    int a[10];
    const int (*p)[10] = &a; // OK in C++
    

    Trying to do the same in C will result in an error

    int a[10];
    const int (*p)[10] = &a; /* ERROR in C */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this may be a naive question, but, as asked in the object, what is
This question may be too product specifc but I'd like to know if anyone
This question may sound fairly elementary, but this is a debate I had with
You may think this question is like this question asked on StackOverflow earlier. But
There may be more than one way to ask this question, so here's a
This may be a silly question to a graphics guru (which I am not),
This may be a silly question for some of you, but what are Pros/Cons
I suspect I may be wording this question incorrectly (it’s been a while since
i'm a long-time newbie to c#, and this question may be too obvious, so
Alright, I am going to state up front that this question may be too

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.