variables and data types in c++
TRANSCRIPT
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
5a=5;
a
Memory Location reservedAnd 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 KEYWORDSFollowing 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. A2. result3. temppp4. 6B5. B46_34
a
6. a.jok7. 0_klm8. _7ab9. aaaa10._a_b_
X
XX
Result result RESULT resulT
C++ is a Case-Sensitive Languageand 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)