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

Embedded C Programming Questions and Answers

61.

Put the steps the start-up code performs in order.

1. Call main   2. Set the stack pointer   3. Clear the .bss region   4. Copy .data from flash to RAM

Answer: A

The stack must exist before any function is entered, then the initialised statics are copied and the zeroed ones cleared, and only when the C environment is complete is main called. Either order of the two memory operations works, but both must precede main.

Please log in or register to report this question.

Answer: B

Unoptimised code reads memory every time and hides the missing qualifier; optimised code caches the value and the bug appears. It is the single most common explanation for that symptom and should be the first thing looked for.

Please log in or register to report this question.

Answer: C

Alignment padding is inserted to satisfy the strictest member, and for bytes that requirement is one, so the structure needs three bytes and would be padded to four at most. Twelve would mean each byte occupying a word, which no compiler does.

Please log in or register to report this question.

Answer: D

Where a bit field lands within its storage unit is implementation defined, so the same declaration maps differently on two compilers and the register is written wrongly. A mask says exactly which bits are meant and reads the same everywhere.

Please log in or register to report this question.

65.

The value of sizeof(arr)/sizeof(arr[0]) for this array is

uint16_t arr[10];

Answer: A

Twenty bytes divided by two gives ten, which is the element count whatever the element type. The idiom fails silently when applied to a pointer rather than an array, which is why it belongs in the file where the array is defined.

Please log in or register to report this question.

Answer: B

An array parameter decays to a pointer, so the numerator is four or eight bytes rather than the array's size and the count comes out as two or four. The length must be passed as a separate argument, which is what every careful interface does.

Please log in or register to report this question.

Answer: C

Marking a table const both documents the intent and saves the RAM a mutable copy would need, which on a part with two kilobytes is decisive for a table of any size. Some toolchains need a section attribute as well to be certain of it.

Please log in or register to report this question.

Answer: D

An implicit conversion, an unused result or a comparison between signed and unsigned is usually a bug rather than a stylistic matter, and a warning nobody reads is a warning that achieves nothing. Making the build fail is what keeps the count at zero.

Please log in or register to report this question.

Answer: A

Following a value through several calls reveals the null pointer that can only arrive by one path, or the array index that can exceed its bound, which a compiler working a function at a time cannot see. It is also the tool that checks MISRA compliance.

Please log in or register to report this question.

Answer: B

Correct answer: reinterpreting a 32-bit word as four bytes

That is what a union is for, and reading a member other than the one last written is permitted in C for exactly this purpose. The other three misdescribe it: members overlap rather than sit consecutively, only one holds a valid value at a time, and the alignment is the strictest of the members rather than a relaxed one.

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