variables and data types in c++

10
VARIABLES AND DATA TYPES IICT – Lab-8 IN C++

Upload: ameer-khan

Post on 17-Jan-2017

164 views

Category:

Education


2 download

TRANSCRIPT

Page 1: Variables and data types in C++

VARIABLES AND DATA TYPES IICT – Lab-8 IN C++

Page 2: Variables and data types 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’

Page 3: Variables and data types in C++

VARIABLE

Memory

5a=5;

a

Memory Location reservedAnd named as “a”

Page 4: Variables and data types in C++

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++

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++

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++

Result result RESULT resulT

C++ is a Case-Sensitive Languageand so are its Identifiers.

IDENTIFIERS

Page 8: Variables and data types in C++

DATA TYPES

• Character [ char ]• Integer [ int ]• Float [ float ]• Boolean [ bool ]

Page 9: Variables and data types in C++

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++

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)