by
Can we declare a variable be both constant and volatile in C?

1 Answer

0 votes
by
Yes, we can use both constant and volatile together. One of the great use of volatile and const keyword together is at the time of accessing the GPIO registers. In the case of GPIO, its value will be changed by the ‘external factors’ (if a switch or any output device is attached with GPIO), if it is configured as an input. In that situation, volatile plays an important role and ensures that the compiler always read the value from the GPIO address and avoid to make any assumption. After using the volatile keyword, you will get the proper value whenever you are accessing the ports but still here is one more problem because the pointer is not const type so it might be your program change the pointing address of the pointer. So we have to create a constant pointer with a volatile keyword. Syntax of declaration, int volatile * const PortRegister;

Related questions

0 votes
    Can we have a volatile pointer?...
asked Jan 23, 2021 by JackTerrance
0 votes
0 votes
    What is the meaning of the below declarations? 1. const int a; 2. int const a; 3. const int *a; 4. int * const a; 5. int const * a const;c...
asked Jan 21, 2021 by JackTerrance
0 votes
    Why trash rack is used?...
asked Jan 28, 2021 in Education by JackTerrance
0 votes
    What is a volatile variable in C?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
0 votes
    The following are ways to declare a variable in TypeScript, except ________. (1)var 2 (2)var localLength=13 (3)var lengthA:string = "meter" (4)var lengthB:string...
asked Aug 20, 2021 by JackTerrance
0 votes
    Which of these exceptions will be thrown if we declare an array with negative size? (a) IllegalArrayException ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Can we use just the tag name of structures to declare the variables for the same?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    What is a volatile variable and there purpose n Java?...
asked May 19, 2021 in Technology by JackTerrance
0 votes
    The type of a variable that is volatile is _______________ (a) Volatile variable (b) Mutable variable (c) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Can we have a volatile pointer?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    How to declare a pointer to a function in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    Write error message given by C compiler during compilation if we use %d to print float variable Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    LCD Projector can be connected to PC through: (A) HDMI Connection (B) VGA Connection (C) Both of these (D) None of these Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
...