The difference between a const variable and a const variable

What's the difference between:

const variable = 10;

and

const int variable = 10;

Is a variable, standard, interpreted as an integral type if the type is not defined?

+2
source share
4 answers

const variable = 10invalid C ++, but const int variable = 10;-.

The only time I can think of what const variable = 10would be right is if you had a type with a name variableand you had a function with an unnamed parameter of that type that takes a default argument:

typedef int variable;
void foo(const variable = 10);
+8
source

, x int. ++, C C , ISO ++, ++ - .

GCC 4.4 groks "const x = 3;" feed -fms-extensions ( , , MFC)

UPDATE: VS-2005, int,

#pragma warning(disable:4430)
+2
const variable = 10;

++.

+1

Without strict rules (K & RC, etc. Editing: i.e. old C), int is the default type. This, of course, does not mean that the variable has no type, and it has nothing to do with a constant.

0
source

Source: https://habr.com/ru/post/1754484/


All Articles