Object oriented programming language
SUBMITTED BY : -
Tanishq Soni
1
Literals, Primitive Datatypes, Variable, Expressions & Identifiers
LITERALS……?
2
A literal is a notation for
representing a fixed value in
source code.
3
Types Of Literals
1.) Integer literals ,
2.) Floating point literals ,
3.) String Literals ,
4.) Character literals and
5.) Boolean literals.
Integer Literals……?
Integer literals represent different integer values.
There are several ways to use integer literals in
your code. You can specify a literal
with decimal, octal, or hexadecimal base.
4
5
int decimalBase = 123;
int octalBase = 0123;
int hexadecimalBase = 0x123;
cout << "Decimal base " << decimalBase << endl;
cout << "Octal base " << octalBase << endl;
cout << "Hexadecimal base " << hexadecimalBase << endl;
cin.ignore();
The output of this program will be :
Now we can try to print above variables:
PROGRAM :
Floating Point Literals……?
Floating point literals consist of decimal values
(fractional value) that can be followed by the
exponent part if you want.
6
7
float simple = 13.2;
Here, 13.2 is a floating point literal.
We can use the floating point integers with the exponent part. For example:
float value1 = 0.001;
float value2 = 1.0E-3;
Value2 consist of decimal value 1.0) with exponent part E-3. We can print these values to see the output of value2:
cout << "Value1 is " << value1 << endl;
cout << "Value2 is " << value2 << endl;
The output of the program will be as follows:
As you can see, the value1 is same as value2 because 1-3 = 0.001
8
Character Literals……?
Character literals are the sequence of the
characters that are enclosed by single quotes.
These literals are used to represent some
messages and characters: 'Hello World' 'X‘.
If the sequence of characters is followed by L
like L'Text' it means that this literal has to be stored
in variable wchar_t type.
wchar_t ch = L'TutorialCup';
An important note that char variable can store only
one character.
char c = 'H';
9
STRING LITERALS……?
String literals are same as the character literals.
The main difference between string and character
literals is that string literals are enclosed by the
double quote " " .
"This is string literal“
You can use the same special characters in your
string literals as in the characters literals.
10
11
Boolean Literals……?
Boolean literals are used to work with bool data
type. For a Boolean value there are two possible
values: true and false.
It is used in the following way:
bool thisIsTrue = true;
bool thisIsFalse = false;
cout << "True is " << thisIsTrue << "But false is " << thisIsFalse << endl;
cout displays true as "1" and false as "0"
12
Primitive Datatypes……?
These data types are built-in or predefined data
types and can be used directly by the user to
declare variables.
Primitive data types available in C++ are: Integer,
Character, Boolean, Floating Point, Double
Floating Point, Valueless or Void, Wide
Character.
Integer: Keyword used for integer data types is int.
Integers typically requires 2 bytes of memory space
and ranges from -32768 to 32768.
Character: Character data type is used for storing
characters. Keyword used for character data type is
char. Characters typically requires 1 byte of memory
space and ranges from -128 to 127 or 0 to 255.
13
Boolean: Boolean data type is used for storing
boolean or logical values. A boolean variable can
store either true or false. Keyword used for
boolean data type is bool.
Floating Point: Floating Point data type is used
for storing single precision floating point values or
decimal values. Float variables typically requires 4
byte of memory space.
14
Double Floating Point: Double Floating Point data
type is used for storing double precision floating point
values or decimal values. Double variables typically
requires 8 byte of memory space.
void: Void means without any value. Void datatype
represents a valueless entity. Void data type is used for
those function which does not returns a value.
15
Wide Character: Wide character data type is also a
character data type but this data type has size
greater than the normal 8-bit datatype. Represented
by wchar_t. It is generally 2 or 4 bytes long.
16
VARIABLES……?
Variables are simply names used to refer to some
location in memory – a location that holds a value
with which we are working. It may help to think
of variables as a placeholder for a value. You can
think of a variable as being equivalent to its
assigned value.
17
18
EXPRESSIONS……?
Expression is a sequence of operators and
their operands, that specifies a computation.
A combination of variables, constants and
operators that represents a computation forms an
expression. Depending upon the type of operands
involved in an expression or the result obtained
after evaluating expression, there are different
categories of an expression.
Common Expressions
assignment
increment
decrement
arithmetic logical comparison
member
access
other
a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b
++a
--a
a++
a--
+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b
!a
a && b
a || b
a == b
a != b
a < b
a > b
a <= b
a >= b
a[b]
*a
&a
a->b
a.b
a->*b
a.*b
a(...)
a, b
? :
Special operators
20
IDENTIFIERS……?
A C++ identifier is a name used to identify a
variable, function, class, module, or any other user-
defined item.
An identifier starts with a
letter A to Z or a to z or an underscore (_) followed
by zero or more letters, underscores, and digits (0
to 9).
Thank you
21

Literals, primitive datatypes, variables, expressions, identifiers

  • 1.
    Object oriented programminglanguage SUBMITTED BY : - Tanishq Soni 1 Literals, Primitive Datatypes, Variable, Expressions & Identifiers
  • 2.
    LITERALS……? 2 A literal isa notation for representing a fixed value in source code.
  • 3.
    3 Types Of Literals 1.)Integer literals , 2.) Floating point literals , 3.) String Literals , 4.) Character literals and 5.) Boolean literals.
  • 4.
    Integer Literals……? Integer literalsrepresent different integer values. There are several ways to use integer literals in your code. You can specify a literal with decimal, octal, or hexadecimal base. 4
  • 5.
    5 int decimalBase =123; int octalBase = 0123; int hexadecimalBase = 0x123; cout << "Decimal base " << decimalBase << endl; cout << "Octal base " << octalBase << endl; cout << "Hexadecimal base " << hexadecimalBase << endl; cin.ignore(); The output of this program will be : Now we can try to print above variables: PROGRAM :
  • 6.
    Floating Point Literals……? Floatingpoint literals consist of decimal values (fractional value) that can be followed by the exponent part if you want. 6
  • 7.
    7 float simple =13.2; Here, 13.2 is a floating point literal. We can use the floating point integers with the exponent part. For example: float value1 = 0.001; float value2 = 1.0E-3; Value2 consist of decimal value 1.0) with exponent part E-3. We can print these values to see the output of value2: cout << "Value1 is " << value1 << endl; cout << "Value2 is " << value2 << endl; The output of the program will be as follows: As you can see, the value1 is same as value2 because 1-3 = 0.001
  • 8.
    8 Character Literals……? Character literalsare the sequence of the characters that are enclosed by single quotes. These literals are used to represent some messages and characters: 'Hello World' 'X‘. If the sequence of characters is followed by L like L'Text' it means that this literal has to be stored in variable wchar_t type.
  • 9.
    wchar_t ch =L'TutorialCup'; An important note that char variable can store only one character. char c = 'H'; 9
  • 10.
    STRING LITERALS……? String literalsare same as the character literals. The main difference between string and character literals is that string literals are enclosed by the double quote " " . "This is string literal“ You can use the same special characters in your string literals as in the characters literals. 10
  • 11.
    11 Boolean Literals……? Boolean literalsare used to work with bool data type. For a Boolean value there are two possible values: true and false. It is used in the following way: bool thisIsTrue = true; bool thisIsFalse = false; cout << "True is " << thisIsTrue << "But false is " << thisIsFalse << endl; cout displays true as "1" and false as "0"
  • 12.
    12 Primitive Datatypes……? These datatypes are built-in or predefined data types and can be used directly by the user to declare variables. Primitive data types available in C++ are: Integer, Character, Boolean, Floating Point, Double Floating Point, Valueless or Void, Wide Character.
  • 13.
    Integer: Keyword usedfor integer data types is int. Integers typically requires 2 bytes of memory space and ranges from -32768 to 32768. Character: Character data type is used for storing characters. Keyword used for character data type is char. Characters typically requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255. 13
  • 14.
    Boolean: Boolean datatype is used for storing boolean or logical values. A boolean variable can store either true or false. Keyword used for boolean data type is bool. Floating Point: Floating Point data type is used for storing single precision floating point values or decimal values. Float variables typically requires 4 byte of memory space. 14
  • 15.
    Double Floating Point:Double Floating Point data type is used for storing double precision floating point values or decimal values. Double variables typically requires 8 byte of memory space. void: Void means without any value. Void datatype represents a valueless entity. Void data type is used for those function which does not returns a value. 15
  • 16.
    Wide Character: Widecharacter data type is also a character data type but this data type has size greater than the normal 8-bit datatype. Represented by wchar_t. It is generally 2 or 4 bytes long. 16
  • 17.
    VARIABLES……? Variables are simplynames used to refer to some location in memory – a location that holds a value with which we are working. It may help to think of variables as a placeholder for a value. You can think of a variable as being equivalent to its assigned value. 17
  • 18.
    18 EXPRESSIONS……? Expression is asequence of operators and their operands, that specifies a computation. A combination of variables, constants and operators that represents a computation forms an expression. Depending upon the type of operands involved in an expression or the result obtained after evaluating expression, there are different categories of an expression.
  • 19.
    Common Expressions assignment increment decrement arithmetic logicalcomparison member access other a = b a += b a -= b a *= b a /= b a %= b a &= b a |= b a ^= b a <<= b a >>= b ++a --a a++ a-- +a -a a + b a - b a * b a / b a % b ~a a & b a | b a ^ b a << b a >> b !a a && b a || b a == b a != b a < b a > b a <= b a >= b a[b] *a &a a->b a.b a->*b a.*b a(...) a, b ? : Special operators
  • 20.
    20 IDENTIFIERS……? A C++ identifieris a name used to identify a variable, function, class, module, or any other user- defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).
  • 21.