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.
How to implement a edge detection circuit in discrete logic circuit

Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.
This problem tests whether you know that it is legal to typecast an integer to a pointer in order to access an absolute location. The exact syntax varies depending upon one’s style. However, I would typically be looking for something like this: int *ptr; ptr = (int *)0x67a9; *ptr = 0xaa55;
Write down the definition for an integer ‘a’
int a; // An integer
Can the NVIC be relocated
Yes, you did this in your bootloader
Write down the definition for a pointer to an array of ten integers named ‘a’
int (*a)[10]; // A pointer to an array of 10 integers
Big O notation
Needs a whole flash card set for this
What is the importance of using the “const” keyword
(a) The use of const conveys some very useful information to someone reading your code. In effect, declaring a parameter const tells the user about its intended usage. If you spend a lot of time cleaning up the mess left by other people, then you’ll quickly learn to appreciate this extra piece of information. (Of course, programmers that use const, rarely leave a mess for others to clean up…) (b) const has the potential for generating tighter code by giving the optimizer some additional information. (c) Code that uses const liberally is inherently protected by the compiler against inadvertent coding constructs that result in parameters being changed that should not be. In short, they tend to have fewer bugs.
Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.
Use #defines and bit masks. This is a highly portable method, and is the one that should be used. My optimal solution to this problem would be: #define BIT3 (0x1 << 3) static int a; void set_bit3(void) { a |= BIT3; } void clear_bit3(void) { a &= ~BIT3; }
Can a pointer be volatile? Explain your answer.
Yes. Although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer.
What does the folllowing decleration mean?
const int a;
a is a const (read only integer).
What does the folllowing decleration mean
int const a;
?
‘a’ is a const (read only) integer
What does the following declaration mean?
const int *a;
?
‘a’ is a pointer to a const integer
What does the following decleration mean?
int * const a;
Declares ‘a’ to be a const pointer to an integer (i.e., the integer pointed to by a is modifiable, but the pointer is not)
What does the following decleartion mean ?
int const * a const;
Declares ‘a’ to be a const pointer to a const integer (i.e., neither the integer pointed to by a, nor the pointer itself may be modified).