1. Home
  2. Computer Science MCQs
  3. C Programming
  4. In C, how does the declaration int f(); differ from int…

Added 30 Nov -0001

In C, how does the declaration int f(); differ from int f(void);?

  1. The first is a constraint violation, because C requires a parameter list
  2. The first permits exactly one argument of any type, like an old-style call
  3. The first declares no prototype, so any arguments are accepted unchecked Correct answer
  4. Both declare a function taking no arguments and behave identically

Correct answer

C. The first declares no prototype, so any arguments are accepted unchecked

21 views

MCQSEXAM

Explanation

An empty parameter list is an old-style declaration with no prototype, so calls with any number and type of arguments are not checked against it. Writing (void) states explicitly that the function takes no arguments and makes the compiler diagnose mismatched calls. In C++ the two forms are equivalent, and C23 changed f() to mean f(void), which is why older textbooks and newer compilers disagree.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs