C Preprocessor example:
Using the #define statement, how would you declare a manifest constant that returns the number of seconds in a year? Disregard leap years in your answer.
answer:
Using the #define statement, how would you declare a manifest constant that returns the number of seconds in a year? Disregard leap years in your answer.
answer:
#define SECONDS_PER_YEAR
(60 * 60 * 24 * 365)UL
Interviewer is looking for several things here:
• Basic knowledge of the #define syntax (for example, no semi-colon at the end, the need to parenthesize, and so on)
• An understanding that the pre-processor will evaluate constant expressions for you. Thus, it is clearer, and penalty-free, to spell out how you are calculating the number of seconds in a year, rather than actually doing the calculation yourself
• A realization that the expression will overflow an integer argument on a 16-bit machine-hence the need for the L, telling the compiler to treat the variable as a Long
• As a bonus, if you modified the expression with a UL (indicating unsigned long), then you are off to a great start. And remember, first impressions count!
frenz, like this there are very minute but very important things about embedded c, which will decide your fate in interview, try getting more and more embedded c concepts in google
(60 * 60 * 24 * 365)UL
Interviewer is looking for several things here:
• Basic knowledge of the #define syntax (for example, no semi-colon at the end, the need to parenthesize, and so on)
• An understanding that the pre-processor will evaluate constant expressions for you. Thus, it is clearer, and penalty-free, to spell out how you are calculating the number of seconds in a year, rather than actually doing the calculation yourself
• A realization that the expression will overflow an integer argument on a 16-bit machine-hence the need for the L, telling the compiler to treat the variable as a Long
• As a bonus, if you modified the expression with a UL (indicating unsigned long), then you are off to a great start. And remember, first impressions count!
frenz, like this there are very minute but very important things about embedded c, which will decide your fate in interview, try getting more and more embedded c concepts in google
No comments:
Post a Comment