हिंदी

Variables in C++

Advertisements
Maharashtra State Board: Class 11

Variables in C++

A variable in C++ is a named storage location in memory that holds a value that can be modified during the execution of a program. Variables are fundamental components in any programming language, and they are used to store data, perform operations, and manage the flow of information in a program.
The syntax for variables : data-type var1 , var2
The rules for constructing variable names of all types are same

  • The variable name is any combination of alphabets, digits, and underscores.
  • The variable name cannot start with a digit.
  • Uppercase and lowercase letters are distinct.
  • No special symbol other than underscore can be used in a variable name. 
  • There is no limit on the length of the variable name. 

For example : 
Valid variables: i , count , si_int

Invalid variables: $200 , L1 , 1S

Declaration of variables 
Variable declaration in C++ is the process of specifying a name and a data type for a variable so that the compiler reserves appropriate memory space it can be declare anywhere in a program before it is use

  • It tells the compiler what the variable name is.
  • It specifies what type of data the variable will hold

 The syntax for declaring a variable is:
data - type: v1, v2, v3...vn;

For example : float average;
                       int x;
                       double ratio;

Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×