LearnFrenzy
Sign in Take a free test
C

C Programming · Topic 18 of 23

Variable Number of Arguments Questions and Concepts

  • 4 exercises
  • 40 questions
  • ~60 min
  • Answers explained

Interview Questions

Variable Number of Arguments · Study material

Variable Number of Arguments – Interview Questions

1. How do you declare a function that takes a variable number of arguments?

With an ellipsis as the last parameter: int f(int n, ...). Before C23 at least one named parameter is required.

2. Which header and macros are used?

<stdarg.h>: va_list, va_start, va_arg, va_end and va_copy.

3. How does printf know how many arguments it received?

It doesn't – it trusts the format string. Each conversion specification consumes one argument.

4. Why can't va_arg read a float?

float arguments to ... are promoted to double, so they must be read as double. The same applies to char and short (read as int).

5. What does va_copy do?

Copies a va_list at its current position so the remaining arguments can be traversed again.

6. Why do vprintf and vsnprintf exist?

So that your own variadic functions can forward their arguments – ... cannot be passed on directly.

7. What happens if va_arg is called with the wrong type or too many times?

Undefined behaviour: the program may print garbage or crash.

8. What is __VA_ARGS__?

In a variadic macro, the placeholder for the arguments matched by .... C23 adds __VA_OPT__ to emit text only when there are such arguments.

9. Why cast NULL when it is used as a sentinel?

NULL may be defined as plain 0 (an int), which is not guaranteed to be passed like a pointer through ....

10. What changed for variadic functions in C23?

int f(...) with no named parameters is allowed, and va_start takes only the va_list.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About C Programming

C programming is the language most computer science courses start with and the foundation of operating systems, embedded devices and compilers. This section helps you learn C properly – data types, operators, control statements, functions, arrays, strings, pointers, structures, memory allocation and files – and then prove it with hundreds of practice questions explained line by line.

Why it matters

  • C teaches how a computer really works: memory, addresses and how data is stored
  • Pointers and memory questions are a favourite in written tests and technical interviews
  • Once you know C, learning C++, Java and Python becomes much easier
  • Embedded systems, operating systems and many companies' coding rounds still use C

Who it is for

  • School students (Class 11–12 computer science) building a strong programming base
  • College students (B.Tech, BCA, MCA, B.Sc CS) preparing for semester exams, lab work and viva
  • Freshers preparing for campus placements, aptitude-cum-coding tests and technical interviews
  • Anyone preparing for GATE CS or government IT exams

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs that train you to spot bugs quickly
  • Complete programs with solutions and real output, verified on a compiler

Asked in

  • Campus placements
  • TCS, Infosys, Wipro tests
  • Technical interviews
  • GATE CS
  • University exams
  • Government IT exams

How to use this section

  1. Read the study material of a topic and run the examples yourself.
  2. Practise the four exercises – MCQs, output, errors, programs – and read every explanation.
  3. Test yourself with the timed online test, then revise the topics you got wrong.

Search LearnFrenzy

Esc

Quick links