What is C Function Interview Questions- Free Embedded Systems and 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 →

C Function Interview Questions

Test yourself with a quiz on return values, actual and formal arguments and function types, then practise the C function interview questions that embedded companies really ask. Free, from our C programming course.

Reading about functions is one thing; proving that you can predict code without a compiler is another. This closing lecture turns the last four lessons into a hands-on quiz and a bank of C function interview questions with model answers. It is written for anyone following our free C programming course, and the style matches what hiring managers ask in embedded C programming interviews: short code, one subtle trap, and a request to explain your reasoning.

Every output shown in the answers was produced by compiling the program, so you can trust it. Use this page as the practice sheet of our free embedded C course and our free C tutorial: attempt each question on paper first, then open the answer.

What You Will Learn

  • How well you remember return value rules, argument passing and function types
  • How to predict program output that involves comma returns, copies of arguments and type conversion
  • How to spot the classic bugs in short function listings
  • How to answer the most common C function interview questions in clear, confident sentences
  • Which topics to revise before the next chapter

Prerequisites

  • Lectures on the return value, actual and formal arguments, and the four types of functions
  • The no-argument function with a return value, covered in the previous lecture
  • Paper and a pen, so you commit to an answer before looking

How to Use This Quiz

Scoring guide for the twelve multiple-choice questions
  • 11 to 12 correct: you are ready for interview-style function questions.
  • 8 to 10 correct: revise the lecture that matches the questions you missed.
  • Below 8: re-read the four lectures once more and attempt the quiz again tomorrow.

Part 1: Multiple-Choice Questions

Q1. A function ends with return 4, 8, 15;. What value does the caller receive?

  • A) 4
  • B) 15
  • C) 27
  • D) a compile error
Show answer

B) 15. The commas form the comma operator, which evaluates the left parts, discards them and keeps the rightmost value. Most compilers only warn about it.

Q2. Which declaration states clearly, in every C standard, that a function takes no parameters?

  • A) void f();
  • B) void f(void);
  • C) void f(...);
  • D) f;
Show answer

B). Empty parentheses left the parameters unspecified before C23, so wrong calls could compile. Writing void inside the parentheses removes any doubt.

Q3. In int apply_gain(int sample, int gain), the names sample and gain are called:

  • A) actual arguments
  • B) formal arguments
  • C) return values
  • D) global variables
Show answer

B) formal arguments. They sit in the definition and receive the values that the caller supplies, which are the actual arguments.

Q4. A function void bump(int v) { v += 5; } is called as bump(x); where x is 10. What is x afterwards?

  • A) 15
  • B) 10
  • C) 5
  • D) undefined
Show answer

B) 10. C passes a copy of x, so only the function’s own parameter changes.

Q5. What does float half_of(int n) { return n / 2; } return for half_of(9)?

  • A) 4.5
  • B) 4.0
  • C) 5.0
  • D) a compile error
Show answer

B) 4.0. The division uses two integers, giving 4, and only then is the result converted to float. Using 2.0f would give 4.5.

Q6. unsigned char low_byte(int v) { return v; } is called with 0x1234. What is returned?

  • A) 0x12
  • B) 0x34
  • C) 0x1234
  • D) 0x46
Show answer

B) 0x34. Narrowing to a one-byte type keeps only the lowest eight bits. We confirmed the result 0x34 by running the program.

Q7. Which of these cannot be used as an actual argument?

  • A) a constant
  • B) an arithmetic expression
  • C) a call that returns an int
  • D) a call to a void function
Show answer

D). A void call produces no value, so there is nothing to copy into the formal argument.

Q8. A non-void function reaches its closing brace without a return, and the caller uses the result. This is:

  • A) always zero
  • B) undefined behaviour
  • C) always a compile error
  • D) always minus one
Show answer

B). The standard gives no meaning to the value, so you may see anything. The compiler normally only warns.

Q9. Which gcc option turns the missing-return warning into a hard error?

  • A) -Werror=return-type
  • B) -O3
  • C) -g
  • D) -E
Show answer

A). It promotes the return-type warning to an error, so a build with a missing return fails.

Q10. What is the usual signature of an interrupt service routine on an ARM Cortex-M device?

  • A) int name(int)
  • B) void name(int)
  • C) void name(void)
  • D) int name(void)
Show answer

C). The hardware calls the handler through the vector table, so nobody can send arguments or receive a result.

Q11. To which function type does int read_switch(void) belong?

  • A) no arguments, no return value
  • B) no arguments, with a return value
  • C) arguments, no return value
  • D) arguments, with a return value
Show answer

B). The empty parameter list means no data goes in, and the int return type means a value comes out.

Q12. With int apply_gain(int sample, int gain) { return sample * gain; }, what does apply_gain(3.9, 2) return?

  • A) 7
  • B) 6
  • C) 7.8
  • D) a compile error
Show answer

B) 6. With a prototype in scope, 3.9 is converted to int by dropping the fraction, so sample becomes 3 and 3 times 2 is 6.

Part 2: Predict the Output

Read the program carefully and write down the five lines it prints before you open the answer.

#include <stdio.h>

static int pick(void)
{
    return 2, 5, 9;
}

static void twist(int a, int b)
{
    a = a * 2;
    b = b + 1;
    printf("%d %d\n", a, b);
}

static float average(int a, int b)
{
    return (a + b) / 2;
}

static int seven_point_nine(void)
{
    return 7.9;
}

int main(void)
{
    int a = 3, b = 4;

    printf("Q1: %d\n", pick() + 1);

    printf("Q2: ");
    twist(b, a);
    printf("Q2 after: %d %d\n", a, b);

    printf("Q3: %.1f\n", average(3, 4));
    printf("Q4: %d\n", seven_point_nine() * 2);
    return 0;
}
Show output and explanation
Q1: 10
Q2: 8 4
Q2 after: 3 4
Q3: 3.0
Q4: 14

Q1: the comma operator leaves 9, and adding 1 gives 10. Q2: the call twist(b, a) copies 4 into the first parameter and 3 into the second, so the function prints 8 and 4, while main still owns a = 3 and b = 4. Q3: (3 + 4) / 2 is integer division giving 3, then the float conversion makes 3.0. Q4: 7.9 is truncated to 7 on return, and 7 times 2 is 14. The compiler also prints a warning for the comma line, which is a good sign that you should read warnings.

Part 3: Spot the Bug

Bug 1. This function should return 1 for positive input and 0 otherwise.

static int is_positive(int x)
{
    if (x > 0)
        return 1;
}
Show answer

The path where x is zero or negative has no return statement, so the result is undefined. Add return 0; at the bottom, or write return x > 0;.

Bug 2. The author wants this function to give back the smaller and larger of two numbers.

static int min_max(int a, int b)
{
    return (a < b ? a : b), (a < b ? b : a);
}
Show answer

The comma operator keeps only the right-hand value, so the caller always receives the larger number. A single return statement cannot hand back two values; use two small functions now, or pointers and structures later in the course.

Bug 3. A teammate declares a timer helper like this and calls it with a stray argument.

void tick();

int main(void)
{
    tick(1, 2);
    return 0;
}
Show answer

Under older rules empty parentheses mean the parameters are unspecified, so gcc with the C11 setting accepts this wrong call. With the C23 setting it stops with the message too many arguments to function. The fix is to declare void tick(void); and delete the extra values.

Part 4: Programming Challenges

No.TaskFunction typeExpected result
1Write print_status_line, which prints the text STATUS: OKno arguments, no return valueone line of output
2Write sum_of_squares, which adds the squares of 1 to 10 and returns the totalno arguments, with a return value385
3Write count_evens, which counts the even numbers from 1 to 99no arguments, with a return value49

Hint for challenge 2: use a for loop with an accumulator, and cross-check with the formula n(n+1)(2n+1)/6, which gives 385 for n = 10.

Top C Function Interview Questions and Answers

The following C function interview questions appear again and again in embedded and systems interviews. Answer aloud first; then compare your reply with the model answer.

1. What is the difference between actual and formal arguments?

Actual arguments are the values written in a call. Formal arguments are the named parameters in the function definition. At the call, each actual value is copied into the matching formal parameter by position.

2. Is C pass by value or pass by reference?

C is strictly pass by value. The function receives copies, so changing a parameter never changes the caller’s variable. Programmers simulate reference behaviour by passing addresses, which you will learn with pointers.

3. How can a function give back more than one result?

The return statement carries one value. For more, a function can fill variables through pointers, return a structure, or write into an array provided by the caller. Writing return a, b; does not work because the comma operator keeps only b.

4. What does return a, b; actually do?

It evaluates a, discards it, evaluates b and returns b. Compilers warn that the left operand has no effect.

5. What is the difference between void f() and void f(void)?

Before C23, empty parentheses mean the parameter list is unspecified, so argument checking is turned off. With void inside, the function is declared to take nothing. In C23, empty parentheses also mean no parameters, but writing void is portable to every version.

6. What happens if a non-void function ends without a return statement?

Using the value is undefined behaviour. The only exception is main, which in C99 and later returns 0 automatically when it reaches the closing brace.

7. Why are interrupt handlers declared as void with no parameters?

The hardware branches to the handler through the vector table. There is no caller to supply arguments and none to receive a return value, so the signature is void name(void).

8. Give an example of surprising conversion on return.

A function declared to return int that returns 36.9 gives 36, because the fraction is cut. Another is a function returning unsigned char that is given 0x1234, which delivers 0x34 and loses the upper byte.

9. Name the four types of functions in C.

No arguments and no return value, no arguments with a return value, arguments with no return value, and arguments with a return value. Examples are led_toggle, read_switch, set_duty and clamp.

10. Can two functions use the same parameter names?

Yes. Each function has its own scope, so equal names never refer to the same variable. The link between caller and callee is the position of the argument, not its name.

11. In what order are function arguments evaluated?

The C standard does not specify it. Writing a call such as f(i++, i++) is therefore unreliable. Compute the values into separate variables first.

12. Why mark helper functions static?

A static function has internal linkage, so it is visible only in its own source file. That avoids name clashes in large firmware projects and lets the compiler optimise more freely.

13. What is a function prototype and why is it needed?

It is a declaration giving the name, return type and parameter types. With a prototype in scope, the compiler checks every call for count and type and applies the correct conversions.

14. When should you use a parameter instead of a global variable?

Whenever the data changes between calls. Parameters make dependencies visible, simplify testing and avoid problems when an interrupt handler also touches the same global.

15. Is it a bug to ignore a function’s return value?

For pure calculations it is merely wasteful, but ignoring an error code is a real bug. GCC offers the warn_unused_result attribute to make the compiler complain about such calls.

How to Prepare for C Function Interview Questions

Strong candidates do not memorise answers; they trace code. When you see a snippet, write the formal arguments next to the call, note each conversion, and only then predict the result. Practise on paper with the programs in this chapter, change one value at a time, and run the compiler to check your guess. This habit trains the same skill that interviewers test with small puzzles.

Common Mistakes Seen in Interviews

MistakeWhy candidates make itHow to avoid it
Saying C can return two values with a commahabits from other languagesremember the comma operator keeps the last value
Believing a function can change the caller’s variableconfusing names with storagepicture two separate boxes
Ignoring integer division inside a float functionreading the return type before the expressionevaluate the expression first, convert last
Forgetting void in an empty parameter listcopying old codealways write (void)

Best Practices for Answering C Function Interview Questions

Answer like an engineer
  • State the rule first, in one sentence, then give a tiny example.
  • Mention the embedded angle, such as interrupt handlers or register reads, when it fits.
  • Say which standard you are assuming when the answer depends on it, for example C11 versus C23.
  • Admit undefined behaviour openly and explain how you would avoid it.

Summary and Key Takeaways

Chapter recap
  • A function returns one value, and that value is converted to the declared return type.
  • Actual arguments are copied into formal arguments, so the caller’s variables stay safe.
  • Function types are defined by two questions: does data go in, and does a value come out?
  • Always use (void) for no parameters, return on every path and compile with warnings enabled.

Conclusion

Finishing this quiz means you have worked through the core ideas of C functions: return values, argument passing and function types. These ideas are small in size but huge in impact, because in C programming for embedded systems every driver, every protocol stack and every interrupt handler is built from them. If you scored well, move on with confidence to the remaining function types and later to pointers. If a question surprised you, return to the matching lecture and trace its examples by hand. Keep practising through the free embedded C course and the free C tutorial pages, and use these C function interview questions as a weekly warm-up.

Frequently Asked Questions

Are these C function interview questions enough for embedded interviews?

They cover the function fundamentals. Interviewers will also ask about pointers, memory, volatile and interrupts, which later chapters of this course address.

Should I compile the quiz programs myself?

Yes, after predicting the output on paper. Compile with -Wall -Wextra so you also see the warnings discussed in the answers.

Why do some answers mention C23?

Because the newest standard changed the meaning of empty parentheses in a declaration. Knowing both behaviours shows depth in an interview.

What if my output differs from the answer?

Check the compiler flags and standard version first, then trace each call and conversion step by step. Undefined behaviour can differ between compilers.

Where can I practise more?

Rewrite the programs in this chapter with different values, and try the three programming challenges again with new targets.

Finished the Function Quiz?

Keep your streak going with the next lecture of the free C programming course, or revisit the course index to review earlier chapters.

💬 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 →