Variable Type Declaration

Floating Point Numbers

  • Used to represent numbers with fractional values
  • Or numbers representing Power to represent very large and small number
  • Example 0.05 or 0.5^-16

Float Types In C++

There are two type of floating Type variable

1. Float

2. Double

Float- Float is 32 bit (4 byte long)

Double- Float is 64 bits long (8 bytes)

const Float – can not be changed . Lets say we need to save value of certain number , and we want to make sure that its value can not be changed for example PIE =3.14

so

const float=3.14;

Characters

  • A Character has a size of 8 bits. The value range is 00000000 to 11111111. It is used to determine characters.
  • It normally uses ASCI Encoding. We have codes for all characters and symbols. Even it have code for space A=65 B =66, 0=48

Representing Character in C++

char = 65;

char = 0X4e

char = ‘A’

Strings

Array of characters binded together

It ends with ;

Capture

har greet[6]= {‘H’, ‘e’, ‘l’, ‘l’, ‘o’,’1′};Individual characters can be accessed or changed in a string .

Declaring Strings

#include<iostream>
using namespace std;
main()
{
char greet[6]={“hello”}
cout<<greet;}

Question What Will happen if 6 character word instead of 5 in above program

Question : How can we take input value of string

Booleans

Take any one value out of 1 (True of False). Can be declared as constant.

Question : Add two numbers and display out put

Naming Variables in C++

For naming purpose we may use any combination of A to Z or 0 to 9 and underscore (“_”). The name can not start with any number. Can be started with _. We can not use key word for naming like cout or cin.

Type of Declarations

· char

· int

· float

· bool

These declarations tells us what type of values can be stored , in these variables. It helps compiler to allocate the memory required for different operations.

Qualifiers:

Qualifiers help us to tune fine the memory allocation of a variable .

Short int à 2 bytes

Long int à 4 or 8 bytes

Leave a comment