Variable declaration syntax in C++-E3 school


 In this tutorial Variable Declaration in C++.Complete guide Variable and Variable Declaration. I hope 

Easy to Understand.Best of luck.

Question :

C++ Variables: 

 Variables are containers for storing data value. In c++, there are different types of variables.other types of variables two main types, Global Variable, Local Variable.

For Example:

  1. Int 
  2. Char
  3. Bool
  4. Float
  5. Long 
  6. String
  7. Double

Difference Between Variable and Data Type:

Variables Store Information data type store specific information to be store variables 

For Example:

string name = "Jack"

Here string is a data type("string") and tells variables called name("name") to store text(Jack).

Explain Variable :

1).Int (Integer)

  1. Stor Integer Whole number
  2. Without decimal 
  3. 123 to -123 Store 
  4. 4-byte Size 

For Example

  1. 1,2,12,45 are store whole number, not store point number

Not Example

  1. Numbers that are not integers 1.43, 1  3/4, 3.14, are different numbers.


Double OR Float

  1. Store floating-point numbers
  2. with decimal
  3. For Example 
  4.  19.99 to -19.99
  5. 8 byte

Double and Float

Same Rule but the difference only float 32-bit floating-point data_type. A double 64-bit floating-point number.

Bool:

  1. Store Values with Two States 
  2. Yes / NO
  3.  ON /OFF
  4. True /False

Long

  1. store the integer data higher range 
  2. 4-byte 32-bit  system 
  3. 8-byte 64-bit system
For Example
  • long int a=-2147483648  

Char(Character)

  1. store single characters 
  2. such as 'a'  or 'b'
  3. Char value is surrounded by single quotes
  4. 1 byte
  5. -128 to 127 or 0 to 255
For example 
char letter = 'A';

String 

  1.  store text
  2. such as "Hello World"
  3. String values are surrounded by double quotes "  -- "
For Example
  1. string myText="Hello"
 store text hello
Difference Between String and Char
Char VS String

1).Char

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.   char myGrade = 'B';  //char only use single quotes '-------'
  6.   cout << myGrade;
  7.   return 0;
  8. }

2).String 

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.   char myGrade = "B";  //char only use double 7 quotes '-------'
  6.   cout << myGrade;
  7.   return 0;
  8. }

To understand the point.
 Watch Video 



Post a Comment

Virtually nothing is impossible in this world if you just put your mind to it and maintain a
positive attitude.

Previous Post Next Post