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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:15:39+00:00 2026-06-17T07:15:39+00:00

In C, what’s the difference between a static const int and a const int

  • 0

In C, what’s the difference between a static const int and a const int in terms of memory alocated?

void f(int *a)
{
    static const int b = 10;
    const int c = 20;

    *a = b + c;
}

Will b only consume sizeof(int)? And c, will it consume sizeof(int) for the 20 value, and sizeof(int), plus a copy instruction during f execution?

  • 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-17T07:15:40+00:00Added an answer on June 17, 2026 at 7:15 am

    Given that both constants are known inside the function, what’s to stop the compiler from making it *a = 30;? Neither b nor c MUST have storage in this example.

    If there is storage needed:

     static const int b = 10;
    

    will take up one sizeof(int) [possibly more space is used due to padding, depends on what comes before and after a in the data section, and there is nothing stating how much padding the compiler will provide for any given scenario – whatever is necessary to make things “work” on the system the compiler is targetting]. Depending on the architecture of the system, there may be code required to set b = 10 [see below about the size of that].

     const int c = 20; 
    

    Will possibly take up sizeof(int) bytes on the stack, but there will also be code to initialize b to 20 – which could be any small number – 2, 3, 5, 6, 7, 8, 16 or some such, depending on processor architecture and the type of instrucitons required to get that job done. Of course, the compiler could just use 20 directly wherever it needs to.

    But all that is required by the compiler is that *a is set to 30 some way or another. Everything else is “up to the compiler”.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.