C Functions Quiz Interview Questions- Embedded C Programming Training In Hyderabad

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

PREV_LEC  |  NEXT_LEC

Free C Programming Course · Functions Practice Lab

C Functions Quiz Interview Questions

A practice lab with output-prediction puzzles, error-spotting drills, concept questions and C functions interview questions for embedded C programming.

Reading about functions is only half of learning them. The other half is testing yourself until the rules feel automatic. This lab closes the functions section of our free C programming course with a quiz and a bank of C functions interview questions that recruiters for embedded C programming roles really ask. Try each question on paper first, then open the answer. Every output in the answers was produced by compiling and running the program with GCC.

If you are working through this free C tutorial in order, you have already met each idea tested here: argument matching, pass by value, scope, static variables, the return statement, evaluation order and mutual recursion.

What You Will Learn

  • How to check yourself on every major topic of the functions chapter
  • How to answer C functions interview questions clearly and concisely
  • How to recognize compile errors before tracing any values
  • Which mistakes cost the most marks in written tests and screening rounds

Prerequisites

Complete the previous lectures on argument matching, pass by value, the return statement and tracing function calls. This final lesson of the free embedded C course functions block assumes you know them.

Quick Revision Table

TopicOne-line rule
Argument countWith a prototype, a wrong count is a compile error
Pass by valueThe callee changes a copy, never the caller’s variable
ScopeThe innermost declaration of a name wins
Parameter redeclarationA same-named local in the outermost block is an error
Static localInitialized once, keeps its value between calls
Return with commasOnly the last expression is returned
Float to int argumentTruncates toward zero
Same variable twice in one callUndefined behavior

Part A: Output Puzzles for C Functions Interview Questions

Assume each program has the usual #include <stdio.h> line and compiles with a C17 compiler. For each one, write the exact output.

Question A1

int twice(int n) { n *= 2; return n; }

int main(void)
{
    int a = 4, b = twice(a);
    printf("%d %d\n", a, b);
    return 0;
}
Show answer

4 8. The function doubles its own copy and returns 8. The variable a in main is untouched.

Question A2

int g = 10;
void shade(void) { int g = 3; g++; printf("%d ", g); }

int main(void)
{
    shade(); shade();
    printf("%d\n", g);
    return 0;
}
Show answer

4 4 10. The local g hides the global and is rebuilt each call, so it prints 4 both times. The global stays 10.

Question A3

void tick(void) { static int c = 0; c += 2; printf("%d ", c); }

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

2 4 6. The static variable is created once and remembers its value.

Question A4

int mix(int a, int b) { return (a + b, a - b); }

int main(void)
{
    printf("%d\n", mix(9, 4));
    return 0;
}
Show answer

5. The comma operator discards a + b and returns a - b. The compiler warns that the left operand has no effect.

Question A5

double avg(int a, int b) { return (a + b) / 2; }

int main(void)
{
    printf("%.1f\n", avg(3, 4));
    return 0;
}
Show answer

3.0. The sum 7 is divided by the integer 2, which gives 3, and only then converted to double.

Question A6

void show(int x, int y) { printf("%d %d\n", x, y); }

int main(void)
{
    show(3.9, 8 / 3);
    return 0;
}
Show answer

3 2. The value 3.9 is truncated to 3, and 8 / 3 is an integer division giving 2.

Question A7

int digits(int n)
{
    if (n == 0) return 0;
    return n % 10 + digits(n / 10);
}

int main(void)
{
    printf("%d\n", digits(4825));
    return 0;
}
Show answer

19. The function adds the last digit to the sum of the remaining digits: 5 + 2 + 8 + 4.

Question A8

int fun(int k) { static int t = 1; t *= k; return t; }

int main(void)
{
    int s = 0;
    s += fun(2); s += fun(2); s += fun(2);
    printf("%d\n", s);
    return 0;
}
Show answer

14. The static t becomes 2, then 4, then 8. The sum is 2 + 4 + 8.

Question A9

void a(int n);
void b(int n);

void a(int n) { printf("%d ", n); if (n > 0) b(n - 2); }
void b(int n) { printf("%d ", n); if (n > 0) a(n - 1); }

int main(void) { a(5); printf("\n"); return 0; }
Show answer

5 3 2 0. Trace: a(5) prints 5, b(3) prints 3, a(2) prints 2, b(0) prints 0 and stops.

Part B: Spot the Error

Each fragment is wrong. State what the compiler reports and why.

  1. int area(int w, int h);
    ...
    printf("%d", area(4));
    Show answer

    Compile error: too few arguments to function. The prototype demands two values.

  2. int f(int x)
    {
        int x = 3;
        return x;
    }
    Show answer

    Compile error: x redeclared. The parameter and the outermost block share one scope.

  3. x > y ? return x : return y;
    Show answer

    Compile error: expected expression before return. A return is a statement, so it cannot be an operand of the conditional operator. Write return x > y ? x : y;.

  4. int main(void)
    {
        int outer(int a) { return a + 1; }
        return outer(4);
    }
    Show answer

    Nested functions are not standard C. With -pedantic-errors GCC reports an error, and many other compilers reject it outright.

  5. void report(int code);
    ...
    int r = report(3);
    Show answer

    Compile error: void value not ignored as it ought to be. A void function produces no value.

Part C: Concept Check

  1. Which statement about C is true?
    1. C supports pass by reference
    2. C passes every argument by value
    3. C passes arrays by value
    4. C passes structs by reference
    Show answer

    B. Pointers give the effect of references, but the pointer itself is copied.

  2. What is the default value of an uninitialized static local variable?
    1. Garbage
    2. One
    3. Zero
    4. Undefined
    Show answer

    C. Static storage is zero-initialized, unlike automatic locals.

  3. In C23, what does int f(); declare?
    1. Unspecified parameters
    2. A function taking no parameters
    3. A variadic function
    4. An error
    Show answer

    B. C23 made empty parentheses equivalent to (void).

  4. What does return (10, 20, 30); return?
    1. 10
    2. 60
    3. 30
    4. Nothing
    Show answer

    C. The comma operator yields its last operand.

  5. An argument is…
    1. A variable in the definition
    2. A value supplied in the call
    3. A return type
    4. A local variable
    Show answer

    B. The variable in the definition is the parameter.

Part D: Programming Challenges

Write these on your own. Hints are provided, but no solutions, because typing the code yourself is the point.

  1. Swap two integers. Write a function that exchanges the values of two variables in the caller. Hint: the parameters must be pointers.
  2. Range finder. Return both the smallest and largest of four numbers. Hint: use a small struct.
  3. Safe average. Return the average of two integers as a double, with the fraction preserved. Hint: avoid integer division.
  4. Call counter. Write a function that reports how many times it has been called. Hint: a static local.
  5. Parity pair. Implement an odd and even test using two functions that call each other. Hint: forward declarations.

C Functions Interview Questions and Answers

These are the questions that appear most often in embedded screening rounds. Practice saying each answer aloud in two or three sentences.

1. What is the difference between a function declaration and a definition?

A declaration, or prototype, tells the compiler the name, parameter types and return type. A definition also supplies the body that generates the code. A function may be declared many times but defined once.

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

Always pass by value. When a function needs to modify a caller’s object, you pass the object’s address, and the address itself is copied.

3. What is a static local variable and when would you use it?

It is a local variable with static storage duration. It is initialized once and keeps its value between calls. Typical uses are call counters, debounce state and one-time initialization flags.

4. What happens if you call a function with the wrong number of arguments?

With a visible prototype, it is a compile error. Without one, older C versions compile it and the behavior is undefined, which on ARM means the callee reads stale register values.

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

Before C23, the first meant unspecified parameters, while the second meant none. In C23 both mean no parameters. Writing (void) is the portable choice.

6. Can a function return more than one value?

Not through the return statement alone. Use a struct, output pointers, or a status code combined with a pointer.

7. Why is it dangerous to return the address of a local variable?

The local variable lives in the function’s stack frame, which is reused after the function returns. The pointer then refers to memory that may hold anything.

8. What is the purpose of function prototypes?

They let the compiler check argument counts and types and insert needed conversions. They also allow functions to be called before their definitions appear.

9. What is recursion and what are its risks on a microcontroller?

Recursion is a function calling itself, directly or through other functions. Each call uses stack memory, so deep or unbounded recursion can overflow a small stack. Always define a base case and a depth limit, or use a loop.

10. What does the comma operator do in a return statement?

It evaluates the left operand, discards it, and the whole expression takes the value of the right operand. Only that last value is returned.

11. What is the order of evaluation of function arguments?

It is unspecified. Code such as passing i++ twice in one call has undefined behavior and must be avoided.

12. When would you use a pointer parameter versus a value parameter?

Use a value for small read-only inputs. Use a pointer when the function must modify the caller’s data, or when copying a large structure would waste time and stack. Use const pointers for large read-only data.

13. Does a parameter hide a global variable of the same name?

Yes. Inside the function the parameter name refers to the parameter. The global is still accessible elsewhere and the compiler can warn about the shadowing with -Wshadow.

14. What is a forward declaration and why is it needed for mutual recursion?

It is a prototype placed before use. In mutual recursion each function calls the other, so one must be declared before the other is defined.

Common Mistakes in C Functions Interview Questions

These are the slips that sink answers to C functions interview questions in written tests and live rounds.

MistakeBetter answer
Giving a number for a program that does not compileCheck argument counts, redeclarations and syntax first
Claiming C has referencesExplain pass by value with pointers
Ignoring integer divisionCheck operand types before the result type
Inventing an output for i++ used twice in one callSay the behavior is undefined
Forgetting that static initialization happens onceTrace the stored value across calls

Best Practices for Practice Sessions

  • Cover the answer, trace on paper, then compile to confirm.
  • Always compile with -Wall -Wextra and read every warning.
  • Rehearse C functions interview questions in a mock session with a friend.
  • Keep a notebook of mistakes and revisit it before interviews.
  • Explain answers aloud, because interviews test communication as well as knowledge.

Key Takeaways

  • Check that a program compiles before tracing its values.
  • Remember copies, scope, static storage and the return rules.
  • Treat unspecified evaluation order as a warning sign, not a puzzle.
  • Practice explaining ideas simply, as interviewers reward clarity.
  • Revisit these C functions interview questions in the week before every interview.

Conclusion

If you could solve most of this lab without looking at the answers, you have a strong command of C functions, the foundation of every firmware project. Keep revisiting the questions you missed, and write the Part D challenges as real programs, compiling and running them yourself. The next section of this free embedded C course moves on to the next topic in the chapter, building on everything you practiced here.

Frequently Asked Questions

How should I prepare for C functions interview questions?

Practice tracing small programs on paper, learn the rules in the revision table, and rehearse short spoken answers.

Are these questions suitable for freshers?

Yes. They cover fundamentals that every embedded fresher is expected to know.

Should I compile every practice program?

Yes, after you have traced it by hand. The compiler confirms your reasoning and shows warnings you may have missed.

Which compiler flags help most while practicing?

Use -Wall -Wextra -std=c17, and add -Wshadow -Wconversion for stricter feedback.

Is this a free course?

Yes. This free C programming course and every free C tutorial on EmbeddedPathashala are available at no cost.

Finished the Functions Section?

Continue your free embedded C course journey and keep building real embedded C programming skills.

PREV_LEC  |  NEXT_LEC

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