0% found this document useful (0 votes)
1K views2 pages

Embedded C Quiz

The document contains a series of multiple choice questions about C programming concepts such as preprocessor directives, macros, loops, pointers, static keyword usage, volatile keyword usage, bitwise operations, and memory mapped I/O. The questions have a single correct answer choice for each.

Uploaded by

Jonathan Schell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views2 pages

Embedded C Quiz

The document contains a series of multiple choice questions about C programming concepts such as preprocessor directives, macros, loops, pointers, static keyword usage, volatile keyword usage, bitwise operations, and memory mapped I/O. The questions have a single correct answer choice for each.

Uploaded by

Jonathan Schell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Which of the following is the most portable way to declare a C preprocessor cons

tant for the number of seconds in a (non-leap) calendar year?


Choose one
#define SECONDS_PER_YEAR 60 * 60 * 24 * 365
#define SECONDS_PER_YEAR 60 * 60 * 24 * 365;
*
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365UL)
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)
-------Which of the following is the most flexible way to declare a C preprocessor macr
o that takes two arguments and returns the smaller of their two values?
Choose one
*
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MIN(A, B) { if (A < B) A; else B; }
#define MIN(A, B) ((A < B) ? A : B)
#define MIN(A, B) A < B ? A : B;
-------Which of the following constructs can be used to create a portable infinite loop
in C?
Choose one
while (1) { ... }
for (;;) { ... }
loop: ... goto loop;
*
All of the above
--------Which of the following statements accurately describes the intended effect of th
e declaration int (* a)[10];?
Choose one
An array of ten integers
*
A pointer to an array of ten integers
An array of ten pointers to integers
An array of ten pointers to functions
--------Which of the following statements accurately describes a use of C's static keywo
rd?
Choose one
A variable declared static within the body of a function maintains its v
alue between function invocations
A variable declared static outside the body of a function can only be ac
cessed by functions within the same module.
*
Both of the above are accurate
Neither of the above are accurate; static is used for function declarati
ons
--------Which of the following statements accurately describes the meaning of the declar
ation int * const x;?
Choose one
*
x is a constant pointer to an integer
x is a pointer to a constant integer
x is a constant integer value
None of the above; it's an invalid C declaration

--------Which of the following items should generally be declared using C's volatile key
word?
Choose one
A memory-mapped peripheral status register
A global variable used within an interrupt service routine
A global variable used by multiple tasks in a multi-threaded application
*
All of the above
---------Which of the following code snippets can be used to reset the least-significant
bit of x?
Choose one
x & 0x01;
x & ~0x01;
x | ~0x01;
*
x &= ~0x01;
--------Which ANSI C compilers allow a variable to be declared both volatile and const?
Choose one
*
All ANSI C compilers allow this
No ANSI C compilers allow this; it is a K&R C holdover
Most ANSI C compilers allow this
Only the GNU C compiler allows this
----------Which of the following is a correct way to write the value 0xAA55 to physical me
mory address 0x67A9?
Choose one
uint16_t * p = (uint16_t *) 0x67A9; p = 0xAA55;
uint16_t * p = (uint16_t *) 0xAA55; p = 0x67A9;
*
* (uint16_t * const) (0x67A9) = 0xAA55;
* (uint16_t * const) (0xAA55) = 0x67A9;

You might also like