Interview Questions Flashcards
Common Interview Questions you have personally experienced
What do the following incomplete declarations mean? const int a; int const a;
The first two mean the same thing, namely a is a const (read-only) integer. The third means a is a pointer to a const integer (i.e., the integer isn’t modifiable, but the pointer is). The fourth .
Bit Banding, what is it used for
Used in the arm architecture to accomplish masking without the risk of race conditions. Ideal for monitoring bit status’s
Write down the definition for a pointer to a pointer to an integer ‘a’
int **a; // A pointer to a pointer to an integer
Write down the definition for an array of ten pointers to integers, named ‘a’
int *a[10]; // An array of 10 pointers to integers
What does the keyword const mean?
“Read-Only”
Write down the definition for a pointer to an integer ‘a’
int *a; // A pointer to an integer
Write down the definition for an array of ten integers named ‘a’
int a[10]; // An array of 10 integers
What does the keyword volatile mean? Give three different examples of its use.
A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the optimizer must be careful to reload the variable every time it is used instead of holding a copy in a register. Examples of volatile variables are: (a) Hardware registers in peripherals (e.g., status registers) (b) Non-stack variables referenced within an interrupt service routine. (c) Variables shared by multiple tasks in a multi-threaded application.
Write down the definition for a pointer to a function that takes an integer as an argument and returns an integer
int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
Write down the definition for an array of ten pointers to functions that take an integer as an argument and return an integer
int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
Charlieplexing
Charlieplexing is a technique for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used e.g. to drive an array of LEDs.
The method uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing. Although it is more efficient in its use of I/O, there are issues that cause it to be more complicated to design and render it impractical for larger displays. These issues include duty cycle, current requirements and the forward voltages of the LEDs.
What are the uses of the keyword “static” ?
Static has three distinct uses in C: (a) A variable declared static within the body of a function maintains its value between function invocations. (b) A variable declared static within a module [1], (but outside the body of a function) is accessible by all functions within that module. It is not accessible by functions within any other module. That is, it is a localized global. (c) Functions declared static within a module may only be called by other functions within that module. That is, the scope of the function is localized to the module within which it is declared. (this is important)
What is wrong with the following function?: int square(volatile int *ptr) { return *ptr * *ptr; }
This one is wicked. The intent of the code is to return the square of the value pointed to by *ptr. However, since *ptr points to a volatile parameter, the compiler will generate code that looks something like this: int square(volatile int *ptr) { int a,b; a = *ptr; b = *ptr; return a * b; } Since it is possible for the value of *ptr to change unexpectedly, it is possible for a and b to be different. Consequently, this code could return a number that is not a square! The correct way to code this is: long square(volatile int *ptr) { int a; a = *ptr; return a * a; }
Ways to decrease power usage
several methods, reduce number of operations, get down into assembly and benchmark to see if your solutions perform faster than the compiled version. Maybe swtich to FPGA. Reduce number of external communications needed.
Can a parameter be both const and volatile? Explain your answer.
Yes. An example is a read only status register. It is volatile because it can change unexpectedly. It is const because the program should not attempt to modify it.