0
doubt regarding coloums
can any one explain when we have to use : this symbol instead of this ;
2 ответов
+ 3
both r diff symbols. we can't use : instead of :
semicolon(;) is use to terminate the line in the code ie why it is called terminator
eg for decleration ie int a=10;
while colon(:) is use in
1. In switch
while writing case 1:
case 2:
2. class <class-name> : <scope> <parent-class>
3. In access specifier of class members
public:
private:
protected:
4 In ternary expression
<expression> ? <true-block> : <false-block>
and many other
+ 2
FYI, this character : is called colon, not coloums. And this character ; is called semicolon.
There are events when colon is used in code, but in no place it was meant to replace semicolon.
* In C++ for-each loop (enhanced for-loop)
for(<type> <identifier> : <container>)
* In class declaration, inheritance specification
class <class-name> : <scope> <parent-class>
* In access specifier of class members
public:
private:
protected:
* In ternary expression, like a shortand of `if-else` statement.
<expression> ? <true-block> : <false-block>
P.S. Possibly there are more to it but I just don't know : )