+ 1
about the variabile name rules, if I try to call a variable "cout", or any other reserved word, will it result into an error, or is it just a good practice?
4 Respuestas
+ 1
it will generate an error
+ 1
yes it will give error and it is a bad practice
0
you know any keyword like cout or something else has pree defined word it has some special meaning like when we know about my mobile balance then we have to type some special key like *123# here is same that is reserved keyword to know balance
0
Basically, any "keyword" in C++ along with other things such as numbers, operators and basically any syntax used in the language. For example:
int 1 = 2;
int 2 = 2;
cout << 1 + 2;
The reason why you can't name variables these things is because the compiler can't tell the difference between the variable called 1 and the number 1, so how does it know whether to output 3 or 4?
A way around this would be to use the variable names int1 and int2, because they aren't part of the C++ syntax and therefore the compiler won't get confused.
I would recommend using a variable identifier like "output" as an alternative to "cout".