Download - Variables and data types in C++
![Page 1: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/1.jpg)
VARIABLES AND DATA TYPES IICT – Lab-8 IN C++
![Page 2: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/2.jpg)
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’
![Page 3: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/3.jpg)
VARIABLE
Memory
5a=5;
a
Memory Location reservedAnd named as “a”
![Page 4: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/4.jpg)
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++
![Page 5: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/5.jpg)
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
![Page 6: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/6.jpg)
ARE THESE VALID IDENTIFIERS?
1. A2. result3. temppp4. 6B5. B46_34
a
6. a.jok7. 0_klm8. _7ab9. aaaa10._a_b_
X
XX
![Page 7: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/7.jpg)
Result result RESULT resulT
C++ is a Case-Sensitive Languageand so are its Identifiers.
IDENTIFIERS
![Page 8: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/8.jpg)
DATA TYPES
• Character [ char ]• Integer [ int ]• Float [ float ]• Boolean [ bool ]
![Page 9: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/9.jpg)
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)
![Page 10: Variables and data types in C++](https://reader036.vdocuments.us/reader036/viewer/2022083105/587dd1ae1a28ab5b5b8b5883/html5/thumbnails/10.jpg)
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)