cpp variables

c++ variables

The Variable is the name of memory location that can used to stored values. it can take different values but take one value at a time.so these all values can change during execution of program. The datatype is associated with every variable and datatype decides what values the variables can accept or take. there are rules for naming variables are same as that for naming identifiers.

Declaration of variables

Here in the Declaration data type may int, float, char, double etc. its depend on your choice how value you want to store. some examples of declaration of variables are-

int x;
float salary;
char grade;
long a;
short s;

In this example x is variable of type int,salary variable is of type float, and grade variable is of type char. The datatype short int can written as int and long int can written as long.we can declare more then one variable in one statement example

int x, float salary, char grade, long a, short s;

Initialization of variables

When a variable is declare it contain garbage value. if we want some value we should assign some initial value to the variable during the declaration. this is known initialization of variable. example-

int x=9;
float salary=1000.9;
char grade=’a’;
long a=89;
short s=7;

Rules for Declaration of variables


1. The variable name should consist of only uppercase and lowercase letters, digits and underscore sign(_).
2. The first character should an alphabet or underscore.
3. The name should not keyword(Reserved words).
4. The C is a case-sensitive, so the uppercase and lowercase are consider different, example NOTE and note are different

Userdefined.h
extern int global=18; //also global
#include<userdefined.h> //import userdefind headerfile. that created already
void globalprint()
{
cout << global;
}

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise