Block-1: Unit-Ii
Block-1: Unit-Ii
UNIT-II
BASICS OF C++
Character Set
The character set is a combination of English language
comprising of the alphabets and the White spaces and
some symbols from the mathematics including the
Digits and the Special symbols. C++ character set
means the characters and the symbols that are
understandable and acceptable by the C++ Program.
These are grouped to create and give the commands,
expressions, words, c-statements, and some of the
other tokens for the C++ Language.
IDENTIFIERS
1. Constants
2. Variables
3. Functions
4. Labels
5. Defined data types
Some naming rules are common in both C and C++. They are as follows:
The identifier name cannot start with a digit, i.e., the first letter should be
alphabetical. After the first letter, we can use letters, digits, or underscores.
In C++, uppercase and lowercase letters are distinct. Therefore, we can say that C++
For the development of code, C supports C++ is known as hybrid language because C++
supports both procedural and
procedural programming. object oriented programming paradigms.
DATA TYPES IN C++
• Primitive Data Types: These data types are built-in or
predefined data types and can be used directly by the
user to declare variables. example: int, char , float, bool
etc. Primitive data types available in C++ are:
– Integer
– Character
– Boolean
– Floating Point
– Double Floating Point
– Valueless or Void
– Wide Character
Derived Data Types
+ Addition
- Subtraction
* Multiplication
/ Division
Greater Than or
>= Equal To 3 >= 5 give us false
Logical AND.
expression1 &&
&& expression2 True only if all the
operands are true.
Logical OR.
|| expression1 || True if at least one of the
expression2
operands is true.
Logical NOT.
! !expression True only if the operand is
false.
Bitwise Operators
Operator Description
| Binary OR
^ Binary XOR
represents memory
& address of the operand # // address of num
Single-line Comments
Single-line comments start with two forward slashes (//).
Example:
//This is a comment
cout << "Hello World!";
Multi-line Comments
Example
Syntax:
setprecision(int n)
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;
int main()
{
// Initializing the decimal
double num = 3.142857142857;
cout << "Before setting the precision: \n"
<< num << endl;
// Using setprecision()
cout << "Setting the precision using"
<< " setprecision to 5: \n"
<< setprecision(5);
cout << num << endl;
// Using setprecision()
cout << "Setting the precision using"
<< " setprecision to 9 : \n "
<< setprecision(9);
cout << num << endl;
return 0;
}
Before setting the precision: 3.14286
Setting the precision using setprecision to 5: 3.1429
Setting the precision using setprecision to 9: 3.14285714