C program output - interview question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C program output - interview question

Given the following code: #define MN 1 /* MAN */ #define RT 2 /* Renault */ #define VT 3 /* Volvo */ #define MT 4 /* Mack */ #define HighLine 1 #define BasicLine 2 #if((INSBrand == VT) || (INSBrand == RT) || (INSBrand == MN)) static void LEDC_vSwitchTachoRedLeds(uint8 u8RangeLow, uint8 u8RangeHigh); static void LEDC_vSwitchTachoGreenLeds(uint8 u8RangeLow, uint8 u8RangeHigh); #if((INSBrand == RT) || (INSBrand == MN)) static void LEDC_vSwitchTachoBlueLeds(uint8 u8RangeLow, uint8 u8RangeHigh); #endif #if((INSBrand == VT) && (INSVar == HighLine)) || (INSBrand == MN)) static void LEDC_vSwitchACCLeds(uint8 u8RangeLow, uint8 u8RangeHigh); #endif #endif What will the program output if: 1) #define INSBrand MT #define INSVar HighLine 2) #define INSBrand RT #define INSVar BasicLine 3) #define INSBrand VT #define INSVar BasicLine 4) #define INSBrand VT #define INSVar HighLine

1st Jul 2022, 9:58 AM
someone said
4 Answers
+ 1
@Ipang, yes. That's why I didn't know the answer to it, either. But the exercise is complete and correct, seeing as how it's an interview question. It seems like I don't know enough about the #if macro, and I thought maybe someone around here knows more than I do and can help me answer it...
2nd Jul 2022, 12:55 AM
someone said
+ 1
The question is not about run-time output. Rather, it is asking about preprocessor output. It is easy to make the simple substitutions that the preprocessor would make and see the outcome. However, you must also understand the structure of the given #if statements. Some are nested. Observe the placement of #endif statements. Below I have indented them to clarify how they are nested: #if((INSBrand == VT) || (INSBrand == RT) || (INSBrand == MN))     ...     #if((INSBrand == RT) || (INSBrand == MN))         ...     #endif     #if((INSBrand == VT) && (INSVar == HighLine)) || (INSBrand == MN))         ...     #endif #endif Now you can determine more easily what code gets generated when you make the substitutions. For example, in problem set 1, the answer is no output because none of the three conditions in the first #if statement are true. Now you can handle the rest. You got this!
2nd Jul 2022, 1:14 PM
Brian
Brian - avatar
0
Not an embedded coder here, but I see only macros for value definitions, followed by conditionals, and static function declarations. I can't see where either one of those functions were invoked, nor any statement exist for printing some output (you asked "What will be the program output if:").
1st Jul 2022, 12:01 PM
Ipang
0
Yes, I knew some people was here before, and they know this much more than me. I hope they see your question and could spare some time to share something, for us and the community to know ...
2nd Jul 2022, 8:16 AM
Ipang