VARIABLES AND DATA TYPES
IICT – Lab-8 IN C++
VARIABLE
• Portion of Memory to Store a Value.
• Each variable needs a unique name that distinguishes it from
others.
• Name of the variable should be a valid C++ Identifier.
a=5;
b=2;
In this, variable names are ‘a’ and ‘b’
VARIABLE
Memory
5
a=5;
a
Memory Location reserved
And named as “a”
IDENTIFIERS
• A valid identifier is a sequence of one or more letters, digits or
underscore “ _ “
• A valid identifier shall always begin with a letter or underscore “ _ “
• A valid identifier CAN’T contain Spaces, punctuation marks or any
other symbols.
• A valid identifier CAN’T start with a digit in any case.
• A valid identifier CAN’T be a Reserved Keyword of C++
RESERVED KEYWORDS
Following are reserved keywords of C++ and can’t be used as
identifiers.
alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break,
case, catch, char, char16_t, char32_t, class, compl, const, constexpr,
const_cast, continue, decltype, default, delete, do, double,
dynamic_cast, else, enum, explicit, export, extern, false, float, for,
friend, goto, if, inline, int, long, mutable, namespace, new, noexcept,
not, not_eq, nullptr, operator, or, or_eq, private, protected, public,
register, reinterpret_cast, return, short, signed, sizeof, static,
static_assert, static_cast, struct, switch, template, this, thread_local,
throw, true, try, typedef, typeid, typename, union, unsigned, using,
virtual, void, volatile, wchar_t, while, xor, xor_eq
ARE THESE VALID IDENTIFIERS?
1. A
2. result
3. temppp
4. 6B
5. B46_34a
6. a.jok
7. 0_klm
8. _7ab
9. aaaa
10._a_b_







X
X
X
Result result RESULT resulT
C++ is a Case-Sensitive Language
and so are its Identifiers.
IDENTIFIERS
DATA TYPES
• Character [ char ]
• Integer [ int ]
• Float [ float ]
• Boolean [ bool ]
DECLARATION OF VARIABLES
• Identifier for variable, followed by its data type.
int a;
float mynumber;
• To declare more than one variables of same type, separate their
identifiers with commas, in single statement.
int a,b,c; int a;
int b;
int c;
(It is exactly same as declaring variables like this)
INITIALIZATION OF VARIABLES
• Assigning a value to the variable from the moment it is declared.
int a=5; (value of a is 5)
float mynumber=2.5; (value of mynumber is 2.5)
int b; (value of b is undertermined)

Variables and data types in C++

  • 1.
    VARIABLES AND DATATYPES IICT – Lab-8 IN C++
  • 2.
    VARIABLE • Portion ofMemory to Store a Value. • Each variable needs a unique name that distinguishes it from others. • Name of the variable should be a valid C++ Identifier. a=5; b=2; In this, variable names are ‘a’ and ‘b’
  • 3.
  • 4.
    IDENTIFIERS • A valididentifier is a sequence of one or more letters, digits or underscore “ _ “ • A valid identifier shall always begin with a letter or underscore “ _ “ • A valid identifier CAN’T contain Spaces, punctuation marks or any other symbols. • A valid identifier CAN’T start with a digit in any case. • A valid identifier CAN’T be a Reserved Keyword of C++
  • 5.
    RESERVED KEYWORDS Following arereserved keywords of C++ and can’t be used as identifiers. alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break, case, catch, char, char16_t, char32_t, class, compl, const, constexpr, const_cast, continue, decltype, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, noexcept, not, not_eq, nullptr, operator, or, or_eq, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_assert, static_cast, struct, switch, template, this, thread_local, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while, xor, xor_eq
  • 6.
    ARE THESE VALIDIDENTIFIERS? 1. A 2. result 3. temppp 4. 6B 5. B46_34a 6. a.jok 7. 0_klm 8. _7ab 9. aaaa 10._a_b_        X X X
  • 7.
    Result result RESULTresulT C++ is a Case-Sensitive Language and so are its Identifiers. IDENTIFIERS
  • 8.
    DATA TYPES • Character[ char ] • Integer [ int ] • Float [ float ] • Boolean [ bool ]
  • 9.
    DECLARATION OF VARIABLES •Identifier for variable, followed by its data type. int a; float mynumber; • To declare more than one variables of same type, separate their identifiers with commas, in single statement. int a,b,c; int a; int b; int c; (It is exactly same as declaring variables like this)
  • 10.
    INITIALIZATION OF VARIABLES •Assigning a value to the variable from the moment it is declared. int a=5; (value of a is 5) float mynumber=2.5; (value of mynumber is 2.5) int b; (value of b is undertermined)