A semicolon (';') is not needed after a function declaration. C++

  • A+
Category:Languages

I just recently took an Intermediate Programming Test, and one of the questions I got wrong was as follows:

A semicolon (';') is not needed after a function declaration.

True or False.

I chose "false" (and please correct me if I'm wrong because I feel like I'm going crazy), a function declaration is what you write before the definition (at the top of the code) so the compiler knows the function call before even calling it, and a function definition is what makes up the function as a whole.

ie.

Declaration:

int func(); 

Definition:

int func() {   return 1; } 

My question is, shouldn't the answer to this be false?

 


You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: