Quiz- Operators Interview Questions for Embedded C: Arithmetic, Relational and Logical-Free Embedded C Programming Course

🚀 Learn BLE on Linux (BlueZ) – Programming Part 1

Hands-on Bluetooth Low Energy course. Special price: ₹399

Enroll Now on Udemy →
💬 Need help or career guidance? Ask us!Contact Us →

MODULE 5 · LESSON 5.1 · PRACTICE

Operators Interview Questions for Embedded C: Arithmetic, Relational and Logical

64 questions: multiple choice, fill-in-the-blank, an expression-value table, true/false, 6 code challenges with real output and 12 detailed interview answers. Treat it as a model for operators interview questions.

64
Questions
Beginner → Advanced
Level
Live score
Auto-graded
Live Score Tracker
0
Correct
0
Wrong
0
Attempted
Answer the auto-graded questions (MCQ, fill-in, true/false) to see your score.

Section 1: Multiple Choice Questions — Arithmetic, Relational and Logical Operators

These operators interview questions in multiple-choice form check the details that cause real firmware bugs. Click an answer; explanations always appear. Answers like this score well in operators interview questions.

1. What is the value of 17 / 5 in C with integer operands?

2. What is the value of 17 % 5?

3. What is -9 / 4 in C99 and later?

4. What is -9 % 4?

5. Which expression computes 2.5 from integers a = 5 and b = 2?

6. What does a relational operator such as 3 < 5 evaluate to?

7. What does 0 < x < 10 do for x = 50?

8. What is 5 && 2?

9. What is !7?

10. In f() && g(), when is g() called?

11. In f() || g(), when is g() called?

12. Which operator has the highest precedence?

13. What is 2 + 3 * 4?

14. What is the result of 10 - 4 - 3?

15. Which statement about signed integer overflow in C is correct?

16. What is stored in uint8_t x = 200 + 100;?

Section 2: Fill in the Blanks

Enter the number each expression produces. Spaces are ignored.

1. 9 / 2 equals

2. 9 % 2 equals

3. -9 / 2 equals

4. -9 % 2 equals

5. 5 == 5 evaluates to

6. 5 != 5 evaluates to

7. !0 evaluates to

8. !!42 evaluates to

9. 3 && 0 evaluates to

10. 3 || 0 evaluates to

11. 1 + 2 * 3 equals

12. (1 + 2) * 3 equals

Section 3: What Does the Expression Evaluate To?

Choose the value of each expression. Typical of operators interview questions.

ExpressionYour answerResult
7 / 201233.55
7 % 201233.55
7 / 2.001233.55
1 / 2 + 1 / 201233.55
5 > 3 && 2 > 401233.55
5 > 3 || 2 > 401233.55
!(5 > 3)01233.55
10 - 2 - 301233.55
2 * 3 % 401233.55
1 + 1 == 201233.55

Section 4: True or False

Quick checks that appear in screening rounds.

1. The remainder operator % can be used with float operands.

2. x / 2 always rounds down.

3. In a || b, b is not evaluated if a is non-zero.

4. A comparison like x == y yields a bool type in C.

5. Unsigned integer arithmetic wraps around modulo 2N.

6. Comparing two float values with == is a reliable test of equality.

7. Multiplication and division have the same precedence and associate left to right.

8. Division by zero for integers is well-defined and returns 0 in C.

Section 5: Code Snippet Challenges

Real program output backs every answer in these code-reading challenges, the second half of operators interview questions.

Challenge 1 — Output?: Division family
#include <stdio.h> int main(void) { int a = 10, b = 3; printf(“%d %d %.2f %d\n”, a / b, a % b, (float)a / b, (int)((float)a / b)); return 0; }

What are the four numbers?

Output:
3 1 3.33 3
10/3 is 3, 10%3 is 1, the float division gives 3.33, and casting that back to int truncates to 3.
Challenge 2 — Output?: Short-circuit and side effects
#include <stdio.h> int main(void) { int x = 5; if (x > 3 && x++ < 10) printf(“A x=%d\n”, x); if (x < 3 && x++ < 10) printf(“B x=%d\n”, x); if (x > 3 || x++ < 10) printf(“C x=%d\n”, x); return 0; }

Which lines print, and what is x each time?

Output:
A x=6
C x=6
A: x > 3 is true so x++ runs (x becomes 6). B: x < 3 is false, so x++ is skipped. C: x > 3 is true so the right side is skipped. x stays 6.
Challenge 3 — Find the bug: = instead of ==
#include <stdio.h> int main(void) { int v = 2; if (v = 0) printf(“zero\n”); else printf(“non-zero, v=%d\n”, v); return 0; }

What is printed and what does GCC say with -Wall?

Output:
non-zero, v=0
GCC with -Wall:
t.c: In function ‘main’:
t.c:5:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    5 |     if (v = 0)  printf("zero\n");
      |         ^
The assignment v = 0 sets v to 0 and the condition is then false. Use ==.
Challenge 4 — Output?: Order of multiply and divide
#include <stdio.h> #include <stdint.h> int main(void) { uint16_t adc = 3000; uint32_t a = adc * 3300 / 4095; uint32_t b = adc * (3300 / 4095); uint32_t c = adc / 4095 * 3300; printf(“%u %u %u\n”, (unsigned)a, (unsigned)b, (unsigned)c); return 0; }

What are the three values for adc = 3000?

Output:
2417 0 0
a multiplies first (9,900,000 / 4095 = 2417). b computes 3300 / 4095 = 0 and gives 0. c computes 3000 / 4095 = 0 and gives 0.
Challenge 5 — Output?: Precedence workout
#include <stdio.h> int main(void) { int a = 1, b = 2, c = 3; printf(“%d\n”, a + b * c – a / b); printf(“%d\n”, (a + b) * (c – a) / b); printf(“%d\n”, a < b < c); printf(“%d\n”, c > b > a); return 0; }

What are the four lines?

Output:
7
3
1
0
Line 1: 1 + 6 – 0 = 7. Line 2: 3 * 2 / 2 = 3. Line 3: (1 < 2) is 1, then 1 < 3 is 1. Line 4: (3 > 2) is 1, then 1 > 1 is 0.
Challenge 6 — Output?: Elapsed ticks across a wrap
#include <stdio.h> #include <stdint.h> int main(void) { uint32_t start = 4294967290u, now = 5u; printf(“%u\n”, (unsigned)(now – start)); int32_t d = (int32_t)(now – start); printf(“%d\n”, (int)d); return 0; }

What does it print?

Output:
11
11
5 - 4294967290 in unsigned arithmetic is 11: five ticks to reach the wrap plus six after it. The cast to int32_t keeps the value 11.

Section 6: Operators Interview Questions for Embedded C (with Detailed Answers)

These operators interview questions mix language lawyering with practical firmware habits. Click a question for a model answer.

Q1. What is the difference between / and % for integers?Basic+
OperatorReturns17 and 5
/quotient (fraction discarded)3
%remainder2

They satisfy (a / b) * b + a % b == a.

Q2. Why does float f = 5 / 2; store 2.0 and how do you fix it?Basic+

The expression 5 / 2 has two int operands, so it is evaluated as an integer division (result 2) before the assignment converts it to float. The destination type does not influence the operation. Fix by making one operand floating: 5 / 2.0f or (float)5 / 2.

Q3. What do relational and logical operators return in C?Basic+

An int that is exactly 1 (true) or 0 (false). Any non-zero value is treated as true when used as an operand. C99 added _Bool for variables, but the expression type is still int.

Q4. Explain short-circuit evaluation and give an embedded example.Basic+

&& stops after a false left operand and || stops after a true one. Embedded example: if (rx_len < BUF_SIZE && buf[rx_len] == 0) checks the index before reading the array; if (cb != NULL && cb(event)) calls the callback only if it is registered.

Placing the guard on the left is essential, because the language guarantees left-to-right evaluation with a sequence point after the first operand.

Q5. Why is if (0 < x < 10) wrong?Intermediate+

It parses as (0 < x) < 10. The inner comparison gives 0 or 1, and both are less than 10, so the condition is always true. Write if (x > 0 && x < 10). GCC warns with -Wall.

Q6. How do you compute a percentage or an ADC voltage without floating point?Intermediate+

Scale in a wide integer type and divide last: percent = done * 100u / total, mv = adc * 3300u / 4095u. Dividing first loses all precision (3300 / 4095 = 0). Check that the product cannot overflow: 4095 * 3300 fits in 32 bits but not in 16.

Q7. Is signed integer overflow defined in C? How does it differ from unsigned?Intermediate+
UnsignedSigned
OverflowWraps modulo 2N (defined)Undefined behavior
Compiler assumptionNone neededMay assume it never happens and delete checks
Safe testa + b < a detects wrapTest before adding: a > INT_MAX - b

For hardware counters and register images, use unsigned types.

Q8. How do you correctly measure elapsed time with a free-running 32-bit tick that wraps?Intermediate+

Subtract the start from the current value using unsigned arithmetic: if ((uint32_t)(now - start) >= timeout_ms). Modular arithmetic produces the right answer across the wrap as long as the interval is shorter than half the counter range. Comparing now >= start + timeout fails when the sum wraps.

Q9. What are the pitfalls of the modulo operator with negative operands, and how do you get a non-negative index?Advanced+

The result takes the sign of the dividend: -1 % 5 is -1, which is not a valid index. For a circular index that may decrease, use (i % N + N) % N or keep the index unsigned. For power-of-two sizes use a mask: i & (N - 1).

Q10. A teammate writes if (flags & MASK == MASK). What happens?Advanced+

Equality has higher precedence than bitwise AND, so it parses as flags & (MASK == MASK), i.e. flags & 1. The test checks only bit 0 and ignores the mask. The correct form is (flags & MASK) == MASK. GCC reports it with -Wparentheses (part of -Wall).

Q11. What is the order of evaluation of function arguments and operands in C? What problems does it cause?Advanced+

Precedence says how the expression is grouped, not the order in which operands are evaluated. The order of evaluating the operands of most operators, and of function arguments, is unspecified. Only &&, ||, ?: and the comma operator impose an order. So f(next(), next()) and i + i++ are unreliable (the latter is undefined behavior). Put side effects in separate statements.

Q12. How does the Cortex-M4 handle integer division and what does that mean for your code?Advanced+

The Cortex-M3/M4 have hardware SDIV and UDIV instructions that take 2–12 cycles (data dependent), so division is cheap but not free. By default division by zero returns 0 without a fault; setting the DIV_0_TRP bit in the Configuration and Control Register makes it raise a UsageFault. The Cortex-M0 has no divide instruction, so the compiler calls a library routine that takes dozens of cycles; in tight loops there, use shifts or reciprocal multiplication.

Study Plan: Using Your Score on These Operators Interview Questions

ScoreMeaningNext step
90–100%ExcellentContinue to Lesson 5.2: bitwise operators.
70–89%GoodRedo Examples 1, 5, 7 and 10.
Below 70%ReviseRe-read theory sections 2, 3, 5 and 7, then retake the quiz.
Next lesson: Lesson 5.2 introduces & | ^ ~ << >>, the operators that act on individual bits and make register programming possible.
💬 Need help or career guidance? Ask us!Contact Us →

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

×

🚀 BLE on Linux (BlueZ)

Hands-on course. Only ₹399

Enroll Now →