EmbeddedRelated.com
Jacob Beningo
Live online course · Jacob Beningo
AI for Embedded Developers
$100 off for EmbeddedRelated readers until Nov 1 · 5 live sessions, Dec 7-11
Discount ends in
16days 07hrs 35min 52sec
Learn More →

(So far, 54 people got it right out of 481 for a success rate of 11%)

(Thank you to Jason Sachs for submitting this question)


What does kapow() return in this C program?

#include <stdint.h>
uint32_t howjadoo(uint32_t prevsum, uint16_t command, uint16_t response)
{
    return prevsum + (command - response);
}
uint32_t kapow()
{
    return howjadoo(100000, 10001, 10002);
}
Pick one:
99999
165535
it depends on sizeof(int)
this is implementation-defined behavior
this is undefined behavior

[ - ]
Comment by Turbonatta●November 2, 2022

Well, I could understand the result if the quiz was written using "int", "unsigned int", "long" and "unsigned long" which are processor dipendent but every I looked it says that uint16_t is 2 bytes and uint32_t is 4 bytes regardless the processor. I am confused.

[ - ]
Comment by QL●November 2, 2022

Interesting quiz! One quick correction to the explanation section, which says "On machines where an int is 8 or 16 bits,...". The int type in C cannot be only 8-bit wide even on 8-bit CPU. This is because the C Standard says that "Basic signed integer type. Capable of containing at least the [−32,767, +32,767] range."

[ - ]
Comment by jms_nh●November 2, 2022
ah -- thanks, I missed that detail!
[ - ]
Comment by rbonvino●November 7, 2022

Good point I didn't know about

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: