Machine-translated by Google. Questions are authored in English.
Top

Embedded C Programming Questions and Answers

1.

The header that declares the fixed-width integer types is

Answer: A

It provides uint8_t, int32_t and their companions, whose widths are the same on every target. Writing int and hoping for sixteen or thirty-two bits is how code stops working when it is moved between an 8-bit and a 32-bit part.

Please log in or register to report this question.

Answer: B

The standard sets a minimum and leaves the rest to the compiler, so it is sixteen bits on many 8-bit toolchains and thirty-two on most 32-bit ones. Depending on the width without saying so is one of the commonest portability faults.

Please log in or register to report this question.

3.

The type to use for a variable that must hold values from 0 to 200 in the least space is

Answer: C

Correct answer: uint8_t

An unsigned 8-bit type holds 0 to 255, which covers the range in one byte. uint16_t and unsigned int would work but waste space, and int8_t reaches only 127 and would overflow. The fixed-width types from stdint.h are used precisely so the size is stated rather than assumed.

Please log in or register to report this question.

4.

The type intended for the result of the sizeof operator is

Answer: D

It is unsigned and wide enough for the largest object the implementation supports, which is why comparing it against a signed int provokes a warning. The pointer difference type is signed and serves a different purpose.

Please log in or register to report this question.

Answer: A

The compiler must then perform every read and write the source asks for, in the order written, rather than caching the value in a register. It says nothing about atomicity and nothing about ordering with respect to other objects.

Please log in or register to report this question.

Answer: B

Correct answer: the data pointed to may not be modified through p

The const before the type qualifies what is pointed at, so *p cannot be assigned through this pointer, while p itself may be moved. Writing uint8_t * const p instead makes the pointer constant and the data writable - the position of the keyword relative to the star is what decides which.

Please log in or register to report this question.

Answer: C

Restricting the name to one translation unit is the C way of making a module's state private, and it is worth doing for every variable that is not part of an interface. Inside a function the same keyword means something related but distinct.

Please log in or register to report this question.

Answer: D

It has static storage duration, so it lives for the whole program and keeps its value from one call to the next. That also makes the function non-reentrant, which matters if it may be called from a task and a handler both.

Please log in or register to report this question.

Answer: A

The handler's call can arrive part way through the task's and both then work on the same variable, so the results interleave. Passing the state in through a parameter, or giving the handler its own copy, is the remedy.

Please log in or register to report this question.

10.

What is the value of x at the end?

uint8_t x = 0x5A;
x &= 0x0F;
x |= 0x80;

Answer: B

Correct answer: 0x8A

\( 0x5A \) is 0101 1010. Masking with \( 0x0F \) keeps the low nibble, giving 0000 1010, or \( 0x0A \). Setting the top bit with \( 0x80 \) gives 1000 1010, or \( 0x8A \). The two operations are the standard idioms: AND with a mask to keep bits, OR with a mask to set them.

Please log in or register to report this question.

Loading…
Tags: Embedded C Programming Questions and Answers || Embedded C Programming MCQ Questions and Answers || Embedded C Programming GK Questions and Answers || Embedded C Programming GK MCQ Questions || Embedded C Programming Multiple Choice Questions and Answers || Embedded C Programming GK || GK on Embedded C Programming || Embedded Systems Questions and Answers || Embedded Systems MCQ Questions and Answers || Embedded Systems GK Questions and Answers || GK on Embedded Systems