0% found this document useful (0 votes)
20 views3 pages

Constants: /N Endl /N

The document discusses different types of variables in C++ including int, double, char, string, and bool. It provides details on the data each can store and how they are declared. Constants are declared with const to make their values unchangeable. Float has less precision than double, so double is generally safer for calculations. Comments can use // for single lines and /* */ for multiple lines.

Uploaded by

Tahreem Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Constants: /N Endl /N

The document discusses different types of variables in C++ including int, double, char, string, and bool. It provides details on the data each can store and how they are declared. Constants are declared with const to make their values unchangeable. Float has less precision than double, so double is generally safer for calculations. Comments can use // for single lines and /* */ for multiple lines.

Uploaded by

Tahreem Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Both \n and endl are used to break lines.

However, \n is used more often and is


the preferred way.
It is up to you which you want to use. Normally, we use // for short comments,
and /* */ for longer.
In C++, there are different types of variables (defined with different
keywords), for example:
 int - stores integers (whole numbers), without decimals, such as 123 or
-123
 double - stores floating point numbers, with decimals, such as 19.99 or
-19.99
 char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
 string - stores text, such as "Hello World". String values are surrounded
by double quotes
 bool - stores values with two states: true or false
The general rules for constructing names for variables (unique identifiers) are:
 Names can contain letters, digits and underscores
 Names must begin with a letter or an underscore (_)
 Names are case sensitive (myVar and myvar are different variables)
 Names cannot contain whitespaces or special characters like !, #, %, etc.
 Reserved words (like C++ keywords, such as int) cannot be used as
names

 Constants
 When you do not want others (or yourself) to override existing variable
values, use the const keyword (this will declare the variable as "constant",
which means unchangeable and read-only):

float vs. double
The precision of a floating point value indicates how many digits the value can
have after the decimal point. The precision of 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.

You might also like