|
INTERVIEW QUESTIONS
C++
VARIABLES IN C++
DETAILS
Question: what are auto static variables and auto extern variables?
Answer: In theory these are called storage classes. These will define the scope and life time of variables or functions.<br><br>There are mainly 4 of them:<br><br>auto is the default storage class for local variables. <br><br>register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size say a word.<br><br>static can also be defined within a function or as a global variable. If this is done, the variable is initalised at compilation time and retains its value between calls ie, inside the function. Because it is initialsed at compilation time, the initalistation value must be a constant. This is serious stuff - tread with care. <br><br>extern defines a variable as global one ie, that is visable to all files irrespective of where it is defined. When you use 'extern' the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined. <br>
|
|
|
Category |
Variables in C++ Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 9058 users |
Added on |
7/19/2011 |
Views |
71322 |
Rate it! |
|
|
Question:
what are auto static variables and auto extern variables?
Answer:
In theory these are called storage classes. These will define the scope and life time of variables or functions.<br><br>There are mainly 4 of them:<br><br>auto is the default storage class for local variables. <br><br>register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size say a word.<br><br>static can also be defined within a function or as a global variable. If this is done, the variable is initalised at compilation time and retains its value between calls ie, inside the function. Because it is initialsed at compilation time, the initalistation value must be a constant. This is serious stuff - tread with care. <br><br>extern defines a variable as global one ie, that is visable to all files irrespective of where it is defined. When you use 'extern' the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined. <br> Source: CoolInterview.com
A static variable in a function is not instantiated at compile time. Rather, it is done when the first call to that function is made. Thereafter, its value can change but it will persist between calls to that function. Source: CoolInterview.com
Answered by: Akshay | Date:
| Contact Akshay
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How is static variable stored in the memory? ( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. how is it keep seperately in the memory).
|
View Answer
|
|
What is difference between followin intialization.
int iVar1; int iVar2 = int();
and which one of two should we prefer always and why?
|
View Answer
|
|
I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?
|
View Answer
|
|
When you inherit a protected class-level variable, who is it available to?
|
View Answer
|
|
Are private class-level variables inherited?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Variables in C++ Interview Questions & Answers - Exam Mode /
Learning Mode
|