C++ Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 





Variables in C++.


Tutorials Cpp

Topic

What is a variable in C++?.



Explanation

A variable defines a location in the memory that holds a value which can be modified later.

Syntax:
   type variable_list;

In the above syntax "type" refers to any one of the C++ data types.

Declaring Variables:

Variables in C++ should be declared before they are used in the code block. It is better to declare it right at the place where its used as this makes the programming much easier. This kind of declaration reduces the errors in the program.

Example:

   #include <iostream.h>
   void main()
    {
    int n = 10;
    cout << "Integer value is:"<< n << '\n';
    }	

Result:
Integer value is: 10

In the above example "n" is an integer variable declared using return type "int".

Variables can also be intialized dynamically at the place of declaration using the expression as below.

Example:
   float area = 3.14159 * rad * rad

In the above example the variable "area" is declared dynamically when it is used.

Naming variables in C++:
  • Always the first character of a variable must be a letter or an underscore.
  • The variable name cannot start with a digit.
  • Other characters should be either letters, digits, underscores.
  • There is no limit for the length of variables.
  • Declared keywords cannot be used as a variable name.
  • Upper and lower case letters are distinct.









Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting