+ 3
What does ":" do in c++
Saw this in my c++ book, yet its not explained there
6 Réponses
+ 9
I think is just Synstax. Just to make code more readeble,
here look
#include <iostream>
using namespace std;
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
See the word special key name public:
so if : in the end is more readeble for a coder to know everithyng after : is public.
until end of scope
+ 8
i’m not sure...
class_derivated: class_base
?
it’s analog to reservated word “extends” in java?
+ 6
You also use it to define labels.
goto error;
...
error:
...
You also use it do define cases in a switch statement.
switch(x){
case 1:
...
}
+ 2
thank you for your answers, learned a lot, I posted a new question that is related to this one. Check that out if you want.
+ 1
Ternary operator also make use of colon, for separating the true and false block of code to execute.
<condition> ? <true block> : <false block>
+ 1
Its a way of seperating a code block. Usually curly bracket do this. But at some poits : is used. Its just syntax. its how the compiler was designed...