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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:06:37+00:00 2026-05-18T21:06:37+00:00

What does const really mean? Read-only seems to encapsulate its meaning for me, but,

  • 0

What does const really mean? Read-only seems to encapsulate its meaning for me, but, I’m not sure I’m right.

If read-only and const are different, could someone tell me why?

What prompted this question was this answer where he states const “just” means read-only in C. I thought that’s all const meant, regardless of whether it was C or C++. What does he mean?

For an answer to the specific differences in const in C vs C++, I’ve created a new question: How does "const" differ in C and C++? as per R..’s suggestion.

  • 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-18T21:06:38+00:00Added an answer on May 18, 2026 at 9:06 pm

    By declaring a variable as const you indicate compiler that you have no intentions of modifying that variable. But it does not mean others don’t have! It’s just to allow some optimization and to be notified by a compile error (note, that it’s mostly compile error, while const == ReadOnly would mean runtime errors).

    const does not mean read only, because you can write const volatile, that would mean it could change by itself anytime, but I have no intentions to modify it.

    EDIT: here is a classical example: consider I’m writing the code that reads current time from a memory-mapped port. Consider that RTC is mapped to memory DWORD 0x1234.

    const volatile DWORD* now = (DWORD*)0x1234;
    

    It’s const because it’s a read-only port, and it’s volatile because each time I will read it it will change.

    Also note that many architectures effectively make global variables declared as const read-only because it’s UB to modify them. In these cases UB will manifest itself as a runtime-error. In other cases it would be a real UB 🙂

    Here is a good reading: http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html

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

Sidebar

Related Questions

This compiles: int* p1; const int* p2; p2 = p1; This does not: vector<int*>
Slightly related to this question , but you don't really need to read that.
I read the documentation on visit_each , but can't really see what exactly it
These last weeks, I found myself using a lot of const everywhere. Not only
I'm really annoyed by const keyword these days, as I'm not quite familiar with
First the question: Why does the removal of const in UnregisterNode() cause failure, but
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have
How does one pass a const char *path to fts_open? I would like to
Does it make any difference in C99 when one writes const int x =
What difference does it make when I use a const parameter in a procedure?

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.