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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:28:42+00:00 2026-06-13T00:28:42+00:00

Possible Duplicate: const in C vs const in C++ I have following code In

  • 0

Possible Duplicate:
const in C vs const in C++

I have following code

In C

int main()
{
    const int k;//allowed but garbage and later we can't modify
    printf("%d",k);
}

o/p=Garbage

In C++

int main()
{
    const int k; //not allowed from here itself
    printf("%d",k);
}

o/p-compile time error

I having doubt what is the use of the const in C if it it is allowed to declare it with out initialization but after it declaration we can’t initialize it.

But is c++ it is good that we can’t declare a const value without initialization.

Is there any use of the variable k in C or it is useless,if we only declare it as later modification is not possible.

  • 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-13T00:28:43+00:00Added an answer on June 13, 2026 at 12:28 am

    It has no use by itself.

    However, there are compiler specific extensions where this becomes useful again.
    C Compilers for embedded platforms, for example, often have extensions that allow to give a variable a fixed address, or as an alias for an memory mapped I/O port.

    The const would indicate / enforce that you only read from that address, for example a memory mapped input port.

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

Sidebar

Related Questions

Possible Duplicate: Modifying a const through a non-const pointer I have the following code:
Possible Duplicate Why can't I have a non-integral static const member in a class?
Possible Duplicate: What is the difference between const and readonly? i have doubt in
Possible Duplicate: Initializing private static members Why I can't initialize non-const static member or
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: Why const parameters are not allowed in C# I am a C++
Possible Duplicate: Convert std::string to const char* or char* Simple question but I'm new
Possible Duplicate: converting C to C# i have problem in converting by c code

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.