|
C++ is a cross-platform language that can be used to create high-performance applications.
C++ was developed by Bjarne Stroustrup at Bell labs in 1979, as an extension to the C language.
C++ gives programmers a high level of control over system resources and memory.
The language was updated 3 major times in 2011, 2014, and 2017 to C++11, C++14, and C++17.
C++ is one of the world's most popular programming languages.
C++ can be found in today's operating systems, Graphical User Interfaces, and embedded systems.
C++ is an object-oriented programming language which gives a clear structure to programs and allows code to be reused, lowering development costs.
C++ is portable and can be used to develop applications that can be adapted to multiple platforms.
C++ is fun and easy to learn!
As C++ is close to C# and Java, it makes it easy for programmers to switch to C++ or vice versa
This tutorial will teach you the basics of C++.
It is not necessary to have any prior programming experience.
To start using C++, you need two things:
There are many text editors and compilers to choose from. In this tutorial, we
will use an IDE (see below).
An IDE (Integrated Development Environment) is used to edit AND compile the code.
Popular IDE's include Code::Blocks, Eclipse, and Visual Studio. These are all
free, and they can be used to both edit and debug C++ code.
Note: Web-based IDE's can work as well, but functionality is limited.
We will use Code::Blocks in our tutorial, which we believe is a good place to start.
You can find the latest version of Codeblocks at http://www.codeblocks.org/downloads/26.
Download the
Let's create our first C++ file.
Open Codeblocks and go to File > New > Empty File.
Write the following C++ code and save the file as
Don't worry if you don't understand the code above - we will discuss it in detail in later chapters. For now, focus on how to run the code.
In Codeblocks, it should look like this:
Then, go to Build > Build and Run to run (execute) the program. The result will look something to this:
Congratulations! You have now written and executed your first C++ program.
When learning C++ at W3Schools.com, you can use our "Run Example" tool, which shows both the code and the result. This will make it easier for
you to understand every part as we move forward:
Code: Result:
Let's break up the following code to understand it better:
Line 1:
Line 2:
Don't worry if you don't understand how
Line 3: A blank line. C++ ignores white space.
Line 4: Another thing that always appear in a C++ program, is
Line 5:
Note: Every C++ statement ends with a semicolon
Note: The body of
Remember: The compiler ignores white spaces. However, multiple lines makes the code more readable.
Line 6:
You might see some C++ programs that runs without the standard namespace library. The
The
You can add as many
To insert a new line, you can use the
Tip: Two
Another way to insert a new line, is with the
Comments can be used to explain C++ code, and to make it more readable. It can also be used to
prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.
Single-line comments start with two forward slashes (
Any text between
This example uses a single-line comment before a line of code:
This example uses a single-line comment at the end of a line of code:
Multi-line comments start with
Any text between
It is up to you which you want to use. Normally, we use
Variables are containers for storing data values.
In C++, there are different types of variables (defined with different keywords), for example:
To create a variable, you must specify the type and assign it a value:
Where type is one of C++ types (such as
To create a variable that should store a number, look at the following example:
Create a variable called myNum of type
You can also declare a variable without assigning the value, and assign the value later:
Note that if you assign a new value to an existing variable, it will overwrite the previous value:
A demonstration of other data types:
The
To combine both text and a variable, separate them with the
To add a variable to another variable, you can use the
To declare more than one variable of the same type,
use a comma-separated list:
All C++ variables must be
identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names in order to
create understandable and maintainable code:
The general rules for constructing names for variables (unique identifiers) are:
When you do not want others (or yourself) to override existing variable values, use the
You should always declare the variable as constant when you have values that are unlikely to change:
You have already learned that
In the following example, the user can input a number, which is stored in the
variable
In this example, the user needs to input two numbers, and then we print the
sum:
Use the correct keyword to get user input, stored in the variable
As explained in the Variables chapter, a variable in C++ must be a specified data type:
The data type specifies the size and type of information the variable will store:
You will learn more about the individual data types in the next chapters.
Add the correct data type for the following variables:
Use
The precision of a floating point value indicates how many digits the value can have
after the decimal point.
The precision of
A floating point number can also be a scientific number with an "e" to indicate the power of 10:
A boolean data type is declared with the
Boolean values are mostly used for conditional testing, which you will learn more about in a later chapter.
The
Alternatively, you can use ASCII values to display certain characters:
The
To use strings, you must include an additional header file in the source
code, the
You will learn more about strings, in our C++ Strings Chapter.
Operators are used to perform operations on variables and values.
In the example below, we use the
Although the
C++ divides the operators into the following groups:
Arithmetic operators are used to perform common mathematical operations.
Ti
Assignment operators are used to assign values to variables.
In the example below, we use the assignment operator (
The addition assignment operator (
A list of all assignment operators:
Comparison operators are used to compare two values.
Note: The return value of a comparison is either true (
In the following example, we use the greater than operator (
A list of all comparison operators:
You will learn much more about comparison operators and how to use them in a later chapter. p: A l
Logical operators are used to determine the logic between variables or
values:
i
Strings are used for storing text.
A
Create a variable of type
To use strings, you must include an additional header file in the source
code, the
Fill in the missing part to create a
st o
The
In the example above, we added a space after firstName to create a space
between John and Doe on output. However, you could also add a space with quotes (
A string in C++ is actually an object, which contain functions that can perform certain operations on strings. For example, you can also concatenate strings with the
It is up to you whether you want to use f all A
WARNING! C++ uses the Numbers are added. Strings are concatenated.
If you add two numbers, the result will be a number:
If you add two strings, the result will be a string concatenation:
If you try to add a number to a string, an error occurs:
To get the length of a string, use the
Tip: You might see some C++ programs that use the
You can access the characters in a string by referring to its index number
inside square brackets
This example prints the first character in
myString:
Note: String indexes start with 0: [0] is the first character. [1] is the second
character, etc.
This example prints the second character in
myString:
To change the value of a specific character in a string, refer to the index
number, and use single quotes:
It is possible to use the extraction operator
However,
From the example above, you would expect the program to print "John Doe", but it only prints "John".
You might see some C++ programs that runs without the standard namespace library. The
It is up to you if you want to include the standard namespace library or not.
C++ has many functions that allows you to perform mathematical tasks on numbers.
The
And the
Other functions, such as
A list of other popular Math functions (from the
Use the correct function to print the highest value of
Very often, in programming, you will need a data type that can only have one of two values, like:
For this, C++ has a
A boolean variable is declared with the
From the example above, you can read that a
However, it is more common to return boolean values from boolean expressions
(see next page).
ASCII values can be found in our ASCII Table Reference.
A Boolean expression is a C++ expression that returns a boolean value:
You can use a comparison operator, such as the greater than (
Or even easier:
In the examples below, we use the equal to (
Booleans are the basis for all C++ comparisons and conditions. You will learn more about conditions (if...else) in the next chapter.
Fill in the missing parts to print the values
C++ supports the usual logical conditions from mathematics:
You can use these conditions to perform different actions for different decisions.
C++ has the following conditional statements:
Use the
Note that
In the example below, we test two values to find out if 20 is greater than
18. If the condition is
We can also test variables:
In the example above we use two variables, x and y,
to test whether x is greater than y
(using the
Print "Hello World" if
Use the
In the example above, time (20) is greater than 18, so the condition is
Use the
In the example above, time (22) is greater than 10, so the first condition is
However, if the time was 14, our program would print "Good day."
There is also a short-hand if else, which is known as the ternary operator
because it consists of three operands. It can be used to replace multiple lines
of code with a single line. It is often used to replace simple if else
statements:
Instead of writing:
You can simply write:
C++ Get Started
C++ Install IDE
mingw-setup.exe
file, which will install the text editor with
a compiler. C++ Quickstart
myfirstprogram.cpp
(File > Save File as):myfirstprogram.cpp
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
Hello World!
Process returned 0 (0x0) execution time : 0.011 s
Press any
key to continue.Learning C++ At W3Schools
myfirstprogram.cpp
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
Hello World!
C++ Syntax
Example
using namespace std;
int main() {
cout << "Hello World!";
return 0;
} Example explained
#include <iostream>
is a
header file library that lets us work with input and output objects, such as
cout
(used in line 5). Header files add functionality to C++ programs.using namespace std
means that we can use names for objects and variables from the
standard library.#include <iostream>
and using namespace std
works. Just think of it as something that (almost) always appears in your program.int main()
. This is called a
function. Any code inside its curly brackets {}
will be executed.
cout
(pronounced "see-out") is an
object used to output/print text. In our example it will output "Hello World".;
.int main()
could also been written as:
int main () { cout << "Hello World! "; return 0;
}
return 0
ends the main function.Omitting Namespace
using namespace std
line can be omitted and replaced with the std
keyword,
followed by the ::
operator
for some objects:Example
int main() {
std::cout << "Hello World!";
return 0;
} C++ Output (Print Text)
cout
object, together with the <<
operator, is used to output values/print text:Example
using namespace std;
int main() {
cout << "Hello World!";
return 0;
} cout
objects as you want. However, note that it does not insert a new line at the end of the output:Example
using namespace std;
int main() {
cout << "Hello World!";
cout << "I am learning C++";
return 0;
} New Lines
\n
character:Example
using namespace std;
int main() {
cout << "Hello World! \n";
cout << "I am learning C++";
return 0;
} \n
characters after each other will create a blank line:Example
using namespace std;
int main() {
cout << "Hello World! \n\n";
cout << "I am learning C++";
return 0;
} endl
manipulator:Example
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "I am learning C++";
return 0;
} C++ Comments
//
).//
and the end of the line
is ignored by the compiler (will not be executed).C++ Multi-line Comments
/*
and ends with */
./*
and */
will be ignored by
the compiler:Example
to the screen, and it is
amazing */
cout << "Hello World!"; Single or multi-line comments?
//
for short comments, and /* */
for longer.C++ Variables
int
- stores integers (whole numbers), without decimals, such as 123 or -123double
- stores floating point numbers, with decimals, such as 19.99 or -19.99char
- stores single characters, such as 'a' or 'B'.
Char values are surrounded by single quotesstring
- stores text, such as "Hello World".
String values are surrounded by double quotesbool
- stores values with two states:
true or falseDeclaring (Creating) Variables
Syntax
int
), and
variable is the name of the variable (such as x or
myName). The equal sign is used to assign values to the variable.Example
int
and assign it the value 15:
cout << myNum; Example
myNum = 10; // Now myNum is 10
cout << myNum; // Outputs 10 Other Types
Example
double myFloatNum = 5.99;
// Floating point number (with decimals)
char myLetter = 'D';
// Character
string myText = "Hello";
// String (text)
bool
myBoolean = true; // Boolean (true or
false) Display Variables
cout
object is used together with the <<
operator to display variables.<<
operator:Add Variables Together
+
operator:C++ Exercises
Test Yourself With Exercises
Declare Many Variables
C++ Identifiers
Example
int minutesPerHour = 60;
// OK, but not so easy to
understand what m actually is
int
m = 60;
myVar
and myvar
are different variables)int
) cannot be used as namesConstants
const
keyword (this will declare the
variable as "constant", which means unchangeable and read-only):Example
myNum = 10; // error:
assignment of read-only variable 'myNum' C++ User Input
cout
is used to output (print) values. Now we will use cin
to get user input.cin
is a predefined variable that reads data from the keyboard with the extraction operator (>>
).x
. Then we print the value of x
:Example
cout << "Type a number: "; // Type a number and
press enter
cin >> x; // Get user
input from the keyboard
cout << "Your number is: " << x;
// Display the input value Good To Know
cout
is pronounced "see-out". Used for output, and uses the insertion operator (<<
)cin
is pronounced "see-in". Used for input, and uses the extraction operator (>>
)Example
int sum;
cout << "Type a number: ";
cin >> x;
cout << "Type another number: ";
cin >>
y;
sum = x + y;
cout << "Sum is: " << sum; C++ Exercises
Test Yourself With Exercises
Exercise:
x
:int x;
cout << "Type a number: ";
>> ;
C++ Data Types
Example
float myFloatNum = 5.99;
// Floating point number
double myDoubleNum = 9.98; // Floating point number
char myLetter = 'D';
// Character
bool
myBoolean = true; // Boolean
string myText = "Hello";
// String Basic Data Types
Data Type
Size
Description
int
4 bytes
Stores whole numbers, without decimals
float
4 bytes
Stores fractional numbers, containing one or more decimals. Sufficient for
storing 7 decimal digits
double
8 bytes
Stores fractional numbers, containing one or more decimals. Sufficient for
storing 15 decimal digits
boolean
1 byte
Stores true or false values
char
1 byte
Stores a single character/letter/number, or ASCII values
C++ Exercises
Test Yourself With Exercises
Exercise:
myNum = 9;
myDoubleNum = 8.99;
myLetter = 'A';
myBool = false;
myText = "Hello World";
Numeric Types
int
when you need to store a whole number without decimals, like 35 or 1000, and float
or double
when you need a
floating point number (with decimals), like 9.99 or 3.14515.float
vs. double
float
is only six or seven
decimal digits, while double
variables have a precision
of about 15 digits. Therefore it is safer to use double
for most calculations.Scientific Numbers
Boolean Types
bool
keyword and can only take the values true
or false
. When the value is returned, true
= 1
and false
= 0
.Example
bool isFishTasty = false;
cout << isCodingFun;
// Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false) Character Types
char
data type is used to store a
single character. The character must be
surrounded by single quotes, like 'A' or 'c':String Types
string
type is used to store a sequence of characters (text).
This is not a built-in type, but it behaves like one in its most basic usage. String values must be surrounded by double quotes:Example
cout << greeting; <string>
library:Example
#include <string>
// Create a string variable
string greeting = "Hello";
// Output string value
cout << greeting; C++ Operators
+
operator to add together two values:+
operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or a variable and another variable:Example
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
Arithmetic Operators
Operator
Name
Description
Example
Try it
+
Addition
Adds together two values
x + y
Try it »
-
Subtraction
Subtracts one value from another
x - y
Try it »
*
Multiplication
Multiplies two values
x * y
Try it »
/
Division
Divides one value from another
x / y
Try it »
%
Modulus
Returns the division remainder
x % y
Try it »
++
Increment
Increases the value of a variable by 1
++x
Try it »
--
Decrement
Decreases the value of a variable by 1
--x
Try it »
C++ Exercises
Test Yourself With Exercises
Assignment Operators
=
)
to assign the value 10 to a variable called x:+=
) adds a value to a variable:
Operator
Example
Same As
Try it
=
x = 5
x = 5
Try it »
+=
x += 3
x = x + 3
Try it »
-=
x -= 3
x = x - 3
Try it »
*=
x *= 3
x = x * 3
Try it »
/=
x /= 3
x = x / 3
Try it »
%=
x %= 3
x = x % 3
Try it »
&=
x &= 3
x = x & 3
Try it »
|=
x |= 3
x = x | 3
Try it »
^=
x ^= 3
x = x ^ 3
Try it »
>>=
x >>= 3
x = x >> 3
Try it »
<<=
x <<= 3
x = x << 3
Try it »
Comparison Operators
1
) or false (0
).>
) to find out if 5 is greater than 3:Example
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3
Operator
Name
Example
Try it
==
Equal to
x == y
Try it »
!=
Not equal
x != y
Try it »
>
Greater than
x > y
Try it »
<
Less than
x < y
Try it »
>=
Greater than or equal to
x >= y
Try it »
<=
Less than or equal to
x <= y
Try it »
Logical Operators
Operator
Name
Description
Example
Try it
&&
Logical and
Returns true if both statements are true
x < 5 && x < 10
Try it »
||
Logical or
Returns true if one of the statements is true
x < 5 || x < 4
Try it »
!
Logical not
Reverse the result, returns false if the result is true
!(x < 5 && x < 10) C++ Strings
string
variable contains a collection of characters surrounded by double quotes:Example
string
and assign it a value:<string>
library:Example
#include <string>
// Create a string variable
string greeting = "Hello"; C++ Exercises
Test Yourself With Exercises
Exercise:
greeting
variable of type string
and assign it the value Hello
. = ;
String Concatenation
+
operator can be used between strings to add them together to make a new
string. This is called concatenation:Example
string lastName = "Doe";
string fullName =
firstName + lastName;
cout << fullName; " "
or ' '
):Example
string lastName = "Doe";
string fullName =
firstName + " " + lastName;
cout << fullName; Append
append()
function:Example
string lastName = "Doe";
string fullName =
firstName.append(lastName);
cout << fullName; +
or append()
. The major difference between the two, is that the append()
function is much faster. However, for testing and such, it might be easier to just use +
.Adding Numbers and Strings
+
operator for both addition and
concatenation.Example
string y = "20";
string z = x + y; // z will be 1020 (a string)
Example
int y = 20;
string z = x + y; String Length
length()
function:Example
cout << "The length of the txt
string is: " << txt.length(); size()
function to get the length of a string. This is
just an alias of length()
. It is completely up to you if you want to use length()
or size()
:Example
cout << "The length of the txt
string is: " << txt.size(); Access Strings
[]
.Change String Characters
Example
myString[0] = 'J';
cout << myString;
//
Outputs Jello instead of Hello
User Input Strings
>>
on cin
to display a string entered by a user:Example
cout << "Type your first name: ";
cin >>
firstName;
// get user input from the keyboard
cout << "Your name is: " <<
firstName;
// Type your first name: John
// Your name is: John cin
considers a space (whitespace, tabs, etc) as a terminating
character, which means that it can only display a single word (even if you type
many words):Example
cout << "Type your full name: ";
cin >>
fullName;
cout << "Your name is: " <<
fullName;
// Type your full name: John Doe
// Your name is: John
That's why, when working with strings, we often use the getline()
function to read a line of text. It takes cin
as the first parameter, and the string
variable as second:Example
cout << "Type your full name: ";
getline (cin, fullName);
cout << "Your name is: " <<
fullName;
// Type your full name: John Doe
// Your name is: John Doe Omitting Namespace
using namespace std
line can be omitted and replaced with the std
keyword,
followed by the ::
operator
for string
(and cout
) objects:Example
#include <string>
int main() {
std::string greeting = "Hello";
std::cout
<< greeting;
return 0;
} C++ Math
Max and min
max(x,y)
function can be used to find the highest value of x and
y:min(x,y)
function can be used to find the lowest value of
x
and y:C++ <cmath> Header
sqrt
(square root), round
(rounds a number) and log
(natural logarithm), can be found in the <cmath>
header
file:Example
#include <cmath>
cout <<
sqrt(64);
cout << round(2.6);
cout << log(2);
Other Math Functions
<cmath>
library) can be found in the table below:
Function
Description
abs(x)
Returns the absolute value of x
acos(x)
Returns the arccosine of x, in radians
asin(x)
Returns the arcsine of x, in radians
atan(x)
Returns the arctangent of x, in radians
cbrt(x)
Returns the cube root of x
ceil(x)
Returns the value of x rounded up to its nearest integer
cos(x)
Returns the cosine of x, in radians
cosh(x)
Returns the hyperbolic cosine of x, in radians
exp(x)
Returns the value of Ex
expm1(x)
Returns ex -1
fabs(x)
Returns the absolute value of a floating x
fdim(x, y)
Returns the positive difference between x and y
floor(x)
Returns the value of x rounded down to its nearest integer
hypot(x, y)
Returns sqrt(x2 +y2) without intermediate overflow or underflow
fma(x, y, z)
Returns x*y+z without losing precision
fmax(x, y)
Returns the highest value of a floating x and y
fmin(x, y)
Returns the lowest value of a floating x and y
fmod(x, y)
Returns the floating point remainder of x/y
pow(x, y)
Returns the value of x to the power of y
sin(x)
Returns the sine of x (x is in radians)
sinh(x)
Returns the hyperbolic sine of a double value
tan(x)
Returns the tangent of an angle
tanh(x)
Returns the hyperbolic tangent of a double value
C++ Exercises
Test Yourself With Exercises
Exercise:
x
and y
.int x = 5;
int y = 10;
cout << (x, y);
C++ Booleans
bool
data type, which can take the values true
(1) or false
(0).Boolean Values
bool
keyword and can only take the values true
or false
:Example
bool isFishTasty = false;
cout << isCodingFun;
// Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false) true
value returns 1
, and false
returns 0
.Boolean Expression
1
(true) or 0
(false).>
) operator to find out if an expression (or a variable) is true:Example
int y = 9;
cout << (x > y); // returns 1 (true), because 10 is higher than 9 ==
) operator to evaluate an expression:Example
cout << (x == 10); // returns 1 (true), because the value
of x is equal to 10 C++ Exercises
Test Yourself With Exercises
Exercise:
1
(for true) and 0
(for false): isCodingFun = true;
isFishTasty = false;
cout << ;
cout << ;
C++ Conditions and If Statements
if
to specify a block of code to be executed, if a specified condition is trueelse
to specify a block of code to be executed, if the same condition is falseelse if
to specify a new condition to test, if the first condition is falseswitch
to specify many alternative blocks of code to be executedThe if Statement
if
statement to specify a block of
C++ code to be executed if a condition is true
.Syntax
// block of code to be executed if the
condition is true
}
if
is in lowercase letters. Uppercase letters (If or IF) will generate an error.true
, print some text:Example explained
>
operator). As x is 20, and y is 18, and we know that 20 is greater than 18, we print to the screen that "x is greater than y".C++ Exercises
Test Yourself With Exercises
Exercise:
x
is greater than y
.int x = 50;
int y = 10;
(x y) {
cout << "Hello World";
}
The else Statement
else
statement to specify a block of code to be executed if the condition is false
.Syntax
// block of code to be executed if the
condition is true
} else {
// block of code to be executed
if the condition is false
}
Example
if (time < 18) {
cout << "Good
day.";
} else {
cout << "Good
evening.";
}
// Outputs "Good evening." Example explained
false
.
Because of this, we move on to the else
condition and print to the screen "Good
evening". If the time was less than 18, the program would print "Good day".The else if Statement
else if
statement to specify a new condition if the first condition is false
.Syntax
// block of code to be executed if
condition1 is true
} else if (condition2) {
// block of
code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false
and condition2 is false
}
Example
if (time < 10) {
cout << "Good
morning.";
} else if (time < 20) {
cout << "Good
day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening." Example explained
false
. The next condition, in the
else if
statement, is also false
, so we move on to the else
condition since condition1 and condition2 is both false
- and print to the screen "Good
evening".Short Hand If...Else (Ternary Operator)
Syntax
Example
if (time < 18) {
cout << "Good
day.";
} else {
cout << "Good
evening.";
} Example
string result = (time < 18) ? "Good day." : "Good evening.";
cout << result;
#include <iostream>
#include <iostream>
#include <iostream>
Run example »
#include <iostream>
#include <iostream>
Run example »
#include <iostream>
Run example »
#include <iostream>
Run example »
#include <iostream>
Run example »
#include <iostream>
Run example »
/* The code below will print the words Hello World!
Run example »
type variable = value;
int myNum = 15;
Run example »
int myNum = 15; // myNum is 15
Run example »
int myNum = 5;
// Integer (whole number without decimals)
// Good
Run example »
const int myNum = 15; // myNum will always be 15
Run example »
int x;
Run example »
int x, y;
Run example »
int myNum = 5;
// Integer (whole number)
Run example »
bool isCodingFun = true;
Run example »
string greeting = "Hello";
// Include the string library
Run example »
int sum1 = 100 + 50;
// 150 (100 + 50)
Run example »
int x = 5;
Try it Yourself »
string greeting = "Hello";
// Include the string library
Run example »
string firstName = "John ";
Run example »
string firstName = "John";
Run example »
string firstName = "John ";
Run example »
string x = "10";
Run example »
string x = "10";
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Run example »
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Run example »
string
myString = "Hello";
Run example »
string firstName;
string fullName;
string fullName;
Run example »
#include <iostream>
Run example »
// Include the cmath library
Run example »
bool isCodingFun = true;
Run example »
int x = 10;
Run example »
int x = 10;
Run example »
if (condition) {
if (condition) {
int time = 20;
Run example »
if (condition1) {
int time = 22;
Run example »
variable = (condition) ? expressionTrue :
expressionFalse;
int time = 20;
Run example »
int time = 20;
|