0
What is the layout to to declare a variableis it intaor int_3or int a3?
1 st lesson of variable last paragraph
6 odpowiedzi
+ 3
int a3; is the correct one
+ 3
If you use "inta" and "int_3" without space after "int" its wrong. If all three are like :
int a ;
int _3 ;
int a3 ;
are all right. Here "a", "_3", "a3" are variable names of data type "int".
Rules for naming variables in C++ :
A variable name should be start with an alphabet or a underscore "_".
A variable name can have alphabets "a to z", "A to Z", numbers "0 to 9" and an underscore "_".
examples:
a
a1
_a
_1
_a1
a_1
a_11
a13
a16_
_3a
abc
_abc
_ab45
ab45
all of these are correct.
+ 2
int a; int _3; int a3; are all right ways to declare an integer variable but the first one is more used.
+ 1
but in ques. we find int a more
+ 1
Yah we can use any variable name. Here in the programs they are more comfortable with int a. But you can use others such as int _a , int a1 , int abc , and so on .
But we cannot declare a variable beginning with a number or special character (except underscore ) .
Example :
int 3n is wrong
int $a is wrong
0
Thanks