Learn C Language from the Best Tutors
Search in
Asked by Hemlatakarla Last Modified
In computer programming, the volatile
qualifier is used to indicate to the compiler that a variable can be changed by some external entity that is not explicitly specified in the program. It is primarily used when working with multi-threaded or embedded systems where variables can be modified by hardware, interrupts, or other threads outside of the normal flow of program execution.
The volatile
keyword informs the compiler not to optimize access to the variable by caching its value in a register or by reordering memory accesses. This is because the value of a volatile variable can change at any time due to external factors that the compiler may not be aware of, so it needs to be re-read from memory every time it is accessed.
Here's an example in C/C++:
volatile int sensorValue; // Declare a volatile integer variable
int main() {
while (1) {
// Read the volatile variable
int reading = sensorValue;
// Perform some operations with the reading
// Compiler won't optimize away the reading
}
return 0;
}
read less
In computer programming, the volatile
qualifier is used to indicate to the compiler that a variable can be changed by some external entity that is not explicitly specified in the program. It is primarily used when working with multi-threaded or embedded systems where variables can be modified by hardware, interrupts, or other threads outside of the normal flow of program execution.
The volatile
keyword informs the compiler not to optimize access to the variable by caching its value in a register or by reordering memory accesses. This is because the value of a volatile variable can change at any time due to external factors that the compiler may not be aware of, so it needs to be re-read from memory every time it is accessed.
Here's an example in C/C++:
volatile int sensorValue; // Declare a volatile integer variable
int main() {
while (1) {
// Read the volatile variable
int reading = sensorValue;
// Perform some operations with the reading
// Compiler won't optimize away the reading
}
return 0;
}
read less
View 1 more Answers
Related Questions
What is C language?
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Brilliant Academy, a reputed B. Tech Tuition...
Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...
Read full article >
Lasya Infotech: An educational Training...
Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...
Read full article >
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
Read full article >
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
Read full article >
Looking for C Language Classes?
Find best C Language Classes in your locality on UrbanPro.
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youFind best tutors for C Language Classes by posting a requirement.
Get started now, by booking a Free Demo Class