Interview Questions Flashcards

Common Interview Questions you have personally experienced

1
Q

What do the following incomplete declarations mean? const int a; int const a;

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 .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bit Banding, what is it used for

A

Used in the arm architecture to accomplish masking without the risk of race conditions. Ideal for monitoring bit status’s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write down the definition for a pointer to a pointer to an integer ‘a’

A

int **a; // A pointer to a pointer to an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write down the definition for an array of ten pointers to integers, named ‘a’

A

int *a[10]; // An array of 10 pointers to integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the keyword const mean?

A

“Read-Only”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write down the definition for a pointer to an integer ‘a’

A

int *a; // A pointer to an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write down the definition for an array of ten integers named ‘a’

A

int a[10]; // An array of 10 integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the keyword volatile mean? Give three different examples of its use.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write down the definition for a pointer to a function that takes an integer as an argument and returns an integer

A

int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write down the definition for an array of ten pointers to functions that take an integer as an argument and return an integer

A

int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Charlieplexing

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the uses of the keyword “static” ?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is wrong with the following function?: int square(volatile int *ptr) { return *ptr * *ptr; }

A

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; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ways to decrease power usage

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can a parameter be both const and volatile? Explain your answer.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to implement a edge detection circuit in discrete logic circuit

A
17
Q

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.

A

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;

18
Q

Write down the definition for an integer ‘a’

A

int a; // An integer

19
Q

Can the NVIC be relocated

A

Yes, you did this in your bootloader

20
Q

Write down the definition for a pointer to an array of ten integers named ‘a’

A

int (*a)[10]; // A pointer to an array of 10 integers

21
Q

Big O notation

A

Needs a whole flash card set for this

22
Q

What is the importance of using the “const” keyword

A

(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.

23
Q

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.

A

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; }

24
Q

Can a pointer be volatile? Explain your answer.

A

Yes. Although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer.

25
Q

What does the folllowing decleration mean?
const int a;

A

a is a const (read only integer).

26
Q

What does the folllowing decleration mean
int const a;

?

A

‘a’ is a const (read only) integer

27
Q

What does the following declaration mean?

const int *a;

?

A

‘a’ is a pointer to a const integer

28
Q

What does the following decleration mean?
int * const a;

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)

29
Q

What does the following decleartion mean ?

int const * a const;

A

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).