By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

confusion of storing variable?

P: 8
would anyone tell me when we take a variabel suppose int a; is it create a memory space? when we access a variable with oject .variablename how it shows the value .please, tell how it works in respect or RAM.
Nov 25 '10 #1
Share this Question
Share on Google+
5 Replies

P: 542
once the variable is initialised it is assigned memory according to its type for a time according to its scope.
Nov 25 '10 #2

P: 2
Thanks. I also want to know how does it stores variable in ram like in structure it stores one after another and in union it stores from one location? plz. send reply i am confused when i do implemention of programm.
Nov 25 '10 #3

Expert Mod 5K+
P: 8,916
That is entirely implementation dependent, the C and C++ standards impose no requirements on the way any given platform chooses to store the data it uses in memory.

If you want an answer at the very least you are going to have to give a lot more detail of what you are doing and what you are trying to understand.
Nov 25 '10 #4

P: 542
Please follow Banfa from now as my understanding limited.
Nov 26 '10 #5

Expert 100+
P: 2,396
The C Standard imposes certain minimal constraints, such as a short must be able to hold values in at least the range -32768 to 32767. A compiler is free to do whatever it wants as long as it satisfies the minimal constraints. For example, there is no constraint that compilers must use two's-complement encoding for integers.

The Standard imposes no constraint on the order in which variables are allocated in memory.

The Standard permits union members to overlap in memory, but I don't recall there being a definite requirement to do so. That is, a lazy compiler could choose to treat union as a synonym for struct.

The point is that these sort of details vary widely between compilers. There is no answer that is both general and accurate.

If you want a general answer then you need to say so; if you want an accurate answer then you need to tell us which specific compiler you need an answer for.
Nov 26 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.