Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • variable in c++

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 195
    Comment on it

    In c++ we use variables to store the value of a number. The type of the value is needed to be declared first because according to that it will allocate the memory to particular variable.
    Every variable is assigned with the unique memory address.
    There are two types of variables:-

    • Local variable
    • Global variable


    LOCAL VARIABLES:-Declaration of local variable is inside the function or we can say that local variables are used only between the curly braces.
    e.g of local variable:

    #include 
    using namespace local;
    
    int main ()
    {
      // Declaration of local variable:
      int x, y;
      int z;
    
      // actual initialization
      x = 5;
      y = 10;
      z = x * y;
    
      cout << z;
    
      return 0;
    }
    

    GLOBAL VARIABLES:-Global variables are declared on the top of the program or we can say outside the function. We can use that variable throughout the program.
    e.g of global variable:

    #include 
    using namespace global;
    
    // Declaration of global variable :
    int m;
    
    int main ()
    {
      // Declaration of local variable:
      int x, y;
    
      // actual initialization
      x = 5;
      y = 10;
      m = x * y;
    
      cout << m;
    
      return 0;
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: