Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C VARIABLES IN C DETAILS

Question: Constant volatile variable declaration is possible or not? if give any one example and reason.

Answer: Constants can be defined by placing the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable (such as hardware devices). This also forces the compiler to retrieve the value of the variable each time it is referenced rather than possibly optimizing it in a register.

Example: An input-only buffer for an external device could be declared as const volatile (or volatile const, order is not important) to make sure the compiler knows that the variable should not be changed (because it is input-only) and that its value may be altered by processes other than the current program.

Category Variables in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.2) By 9032 users
Added on 6/27/2013
Views 69510
Rate it!

Question: Constant volatile variable declaration is possible or not? if give any one example and reason.

Answer:

Constants can be defined by placing the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable (such as hardware devices). This also forces the compiler to retrieve the value of the variable each time it is referenced rather than possibly optimizing it in a register.

Example: An input-only buffer for an external device could be declared as const volatile (or volatile const, order is not important) to make sure the compiler knows that the variable should not be changed (because it is input-only) and that its value may be altered by processes other than the current program.
Source: CoolInterview.com

Answered by: Gurucharan | Date: 6/27/2008 | Contact Gurucharan Contact Gurucharan

The compilation system tries to reduce code size and execution time on all machines, by optimizing code. It is programmer responsibility to inform compilation system that certain code (or variable) should not be optimized.

Volatile Variable
A volatile variable is the one whose values may be changed at any time by some external sources.

Example:

volatile int num;

The value of data may be altered by some external factor, even if it does not appear on the left hand side of the assignment statement. When we declare a variable as volatile the compiler will examine the value of the variable each time it is encountered to see if an external factor has changed the value.

One example of a volatile object might be a buffer used to exchange data with an external device:
int
check_iobuf(void)
{
volatile int iobuf;
int val;

while (iobuf == 0) {
}
val = iobuf;
iobuf = 0;
return(val);
}

if iobuf had not been declared volatile, the compiler would notice that nothing happens inside the loop and thus eliminate the loop
const and volatile can be used together
An input-only buffer for an external device could be declared as const volatile (or volatile const, order is not important) to make sure the compiler knows that the variable should not be changed (because it is input-only) and that its value may be altered by processes other than the current program
Source: CoolInterview.com

Answered by: Gopal Prajapati | Date: 7/6/2008 | Contact Gopal Prajapati Contact Gopal Prajapati

If a variable is both const and volatile, the two modifiers can appear in either order.

Yes it can be declared!!! Source: CoolInterview.com

Answered by: ameya | Date: 8/21/2008 | Contact ameya Contact ameya

Volatile keyword tells the compiler that the value of the variable can change (may be frequently) so that it can avoid the optimization.

Constant means variable can not be assigned a new value the catch here is using the pointer we can change the value. So when we say a variable is both a constant and volatile that means we are instructing the compiler that the variable can not be assigned a new value and its value can be changed by the use of pointer so don't do any optimization. Source: CoolInterview.com

Answered by: vijay | Date: 9/10/2010 | Contact vijay Contact vijay


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.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
How pointer variables are initialized ?
View Answer
What is a pure virtual function?
View Answer
Are the variables argc and argv are local to main()?
View Answer
What are comment line arguments in C programiing? and also give an example.
View Answer
How much memory does a static variable takes?
View Answer
A variable carries a value.(already assigned OR from Scanf..what ever the way). I want to know whether the variable is positive or negative.
Conditions:
-----------
1.NO looping logic should be used such as for ..while..etc.

2.should not use > or <.

3.should not use any numbers except 0.
We can use 0 and equality operator.
How to know the number is positive or negative?
View Answer
How much memory does a static variable takes?
View Answer
Where does global, static, local, register variables, free memory and C Program instructions get stored?
View Answer
1)What is static identifier?


2)Where are the auto variables stored?
View Answer
What is the benefit of using const for declaring constants?


View Answer
What is the difference between declaring a variable and defining a variable?


View Answer
What is an lvalue?


View Answer
Can static variables be declared in a header file?


View Answer
Can a variable be both const and volatile?


View Answer
What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;

a) float
b) float pointer
c) int
d) int pointer

View Answer
A switch statement cannot include

a) constants as arguments
b) constant expression as arguments
c) string as an argument
d) None of the above

View Answer
How to swap the content of two variables without a temporary variable

View Answer
Where are the auto variables stored? What is the use of register variables?

View Answer
What is an lvalue?
View Answer
Can a variable be both const and volatile?
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



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2024 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions