Sei sulla pagina 1di 3

Q: Which of the following is the most portable way to declare a C preprocessor constant for the

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


Answers Correct Answer User Answer
#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)




Q: Which of the following is the most flexible way to declare a C preprocessor macro that takes
two arguments and returns the smaller of their two values?
Answers Correct Answer User Answer
#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;




Q: Which of the following constructs can be used to create a portable infinite loop in C?
Answers Correct Answer User Answer
while (1) { ... }


for (;;) { ... }


loop: ... goto loop;


All of the above




Q: Which of the following statements accurately describes the intended effect of the declaration
int (* a)[10];?
Answers Correct Answer User Answer
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




Q: Which of the following statements accurately describes a use of C's static keyword?
Answers
Correct
Answer
User
Answer

A variable declared static within the body of a function maintains its
value between function invocations


A variable declared static outside the body of a function can only be


Answers
Correct
Answer
User
Answer

accessed by functions within the same module.
Both of the above are accurate


Neither of the above are accurate; static is used for function
declarations




Q: Which of the following statements accurately describes the meaning of the declaration int *
const x;?
Answers Correct Answer User Answer
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




Q: Which of the following items should generally be declared using C's volatile keyword?
Answers
Correct
Answer
User
Answer

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




Q: Which of the following code snippets can be used to reset the least-significant bit of x?
Answers Correct Answer User Answer
x & 0x01;


x & ~0x01;


x | ~0x01;


x &= ~0x01;




Q: Which ANSI C compilers allow a variable to be declared both volatile and const?
Answers Correct Answer User Answer
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




Q: Which of the following is a correct way to write the value 0xAA55 to physical memory
address 0x67A9?
Answers Correct Answer User Answer
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;

Potrebbero piacerti anche