NVIDIA Interview Question
Software Engineer / Developerspointer to the system clock.. ha-ha-ha
I'm curious how you get such a pointer and where you can use it ? You disassemble the timer interrupt handler to find the exact memory location of the counter and then write a device driver to access a privileged memory ? ;)
volatile is useful in multi-threaded programming to inform the compiler that a certain variable is pointed to, let's say, by several threads, and therefore can be subject to volatile changes. This is to prevent the compiler from optimizing out memory access to this variable.
Const - By type qualifying a variable as const we mean that the data in the variable is non modifiable. It should be initialized during its declaration. It cannot be reassigned with another value at a later time. By type qualifying this to a pointer, we mean that the pointer cannot be repointed to some other data, though the data can be changed. Meaning the address contained in the pointer variable cannot change at any time.
static - This qualifier tells the compiler to retain the value of a variable for the lifetime of a program. But its scope exists only within the function where it is declared. The value of variable can change in the program (not like const). These variables retain their values even in between function calls.
Const - To avoid messing up with the data that has to be maintained as constant. Thereby we can secure the data from changes.
volatile - to point data that is subject to frequent changes eg. hardware clock.
static - to count the number of function calls. To count the number of objects instantiated from a class in a program.
In C++, a static member, is something that is global to all the objects of that class. It is like a shared variable between all objects of that class. A static member function, is a function that is class specific, but not object specific. The 'this' pointer does not exist within a static function. Thus it cannot refer to non static members of the class.
i got a doubt..
Can i use a static function declaration in a .h file (say x.h) & use it through out the file (say i ve multiple .c files) where ever that .h file gets included ???
Yes, you can. Preceding the declaration with static defaults to internal linkage for the function which means function can only be accessed within the file in which it has been declared (i.e. those files where you are including your .h file). So, every file will have its own definition (allocated memory for) of your function and hence can be used in any number of files.
Volatile variable: Certain variables maybe required by some outside processes, CPU makes an arrangement to make this happen. It basically doesn't optimize this variable when the memory of the process is optimized while rolling out and other such things.CPU keeps the volatile variable available for any process to use, and change! Same applies to threads.
Static : The static keyword can be used to declare variables, functions, class data members and class functions.By default, an object or variable that is defined outside all blocks has static duration and external linkage. Static duration means that the object or variable is allocated when the program starts and is deallocated when the program ends. External linkage means that the name of the variable is visible from outside the file in which the variable is declared. Conversely, internal linkage means that the name is not visible outside the file in which the variable is declared.
volatile - By type qualifying a variable as volatile, we mean that the data in the variable is subjectable to change often. Usually, this qualifier is used in embedded programming. This tells the compiler that every time it has to look up the value of the variable as it can change any time. Example - a volatile pointer variable pointing to the system clock.
- Metallicatony September 04, 2008