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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:51:09+00:00 2026-05-11T10:51:09+00:00

I wanted to know how the following works @ compiler level. int const iVal

  • 0

I wanted to know how the following works @ compiler level.

int const iVal = 5;  (int&)iVal = 10;  

A bit of m/c or compiler level answer would be great full.

Thanks in advance.

  • 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. 2026-05-11T10:51:09+00:00Added an answer on May 11, 2026 at 10:51 am

    It is undefined behavior.

    In the first line you define a constant integer. Henceforth, in your program, the compiler is permitted to just substitute iVal with the value 5. It may load it from memory instead, but probably won’t, because that would bring no benefit.

    The second line writes to the memory location that your compiler tells you contains the number 5. However, this is not guaranteed to have any effect, as you’ve already told the compiler that the value won’t change.

    For example, the following will define an array of 5 elements, and print an undefined value (or it can do anything it wants! it’s undefined)

    int const iVal = 5; (int&)iVal = 10; char arr[iVal]; cout << iVal; 

    The generated assembly might look something like:

    sub ESP, 9      ; allocate mem for arr and iVal. hardcoded 5+sizeof(int) bytes                 ; (iVal isn't _required_ to have space allocated to it) mov $iVal, 10   ; the compiler might do this, assuming that you know what                 ; you're doing. But then again, it might not. push $cout push 5 call $operator_ltlt__ostream_int add ESP, 9 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to know why the following code crashes. int main( ) { int
I am new to T-SQL and wanted to know why the following works and
I have the following code which works fine, however I wanted to know if
I wanted to know if anybody can explain me the following piece of Javascript
The following is a C++ program using STL vector container. Just wanted to know
I wanted know how the kernel is providing memory for simple C program .
Wanted to know if someone had a suggestion on code or maybe there's a
Just wanted to know if anyone is really using Objects and Collections in Oracle
I wanted to know if there is way to log the mysql queries in
I wanted to know How OS actually makes a program in to process. what

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.