1

What's the effect of int a(); in C++?

Is it equivalent to int a or int a(0)?

And how about char c() and double d()?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
updogliu
  • 6,066
  • 7
  • 37
  • 50

3 Answers3

11

What's the effect of int a(); in C++?

That declares a function, with no parameters, that returns an integer.

Is it equivalent to int a or int a(0)?

No. Each of these declares a variable of integer type; the second also initialises it with the value zero.

And how about char c() and double d()? Thanks.

These also declare functions, with different return types.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
4

int a(); is a function declaration.

int a is declaring a to be of type int.

int a(0) is declaring a to be of type int and initialising it to 0.

char c() and double d() are function declarations also returning char and double respectively.

All the function declarations should be terminated by a ;.

EdChum
  • 376,765
  • 198
  • 813
  • 562
1

Neither, it declares a function.

Stuart Golodetz
  • 20,238
  • 4
  • 51
  • 80