
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What are the basic rules for defining variables in C++?
To declare a variable, you need to know what data type it is going to be of and what its name would be. The variable name has constraints on what you can name it. Following are the rules for naming variables −
- Variable names in C++ can range from 1 to 255 characters.
- All variable names must begin with a letter of the alphabet or an underscore(_).
- After the first initial letter, variable names can also contain letters and numbers.
- Variable names are case sensitive.
- No spaces or special characters are allowed.
- You cannot use a C++ keyword (reserved word) as a variable name.
Here are some examples of acceptable variable names −
mohd Piyush abc move_name a_123 myname50 _temp j a23b9 retVal
Syntax
You can declare variables using the syntax −
datatype variable_name;
For example,
int my_var; float my_float; ...
- Related Articles
- What are the basic scoping rules for python variables?
- What are the basic rules for JavaScript parameters?
- What are the rules for local and global variables in Python?
- What are the basic rules and idioms for operator overloading in C++?
- What are the rules to declare variables in C++?
- What are the rules for naming classes in C#?
- What are the identity rules for regular expression?
- What are the rules for a functional interface in Java?
- What are the rules for the Subscriber interface in Java 9?
- What are the rules for the Subscription interface in Java 9?
- What are the rules for the Publisher interface in Java 9?
- What are the golden rules for handling your money?
- What are the rules for calling the superclass constructor C++?
- What are the scoping rules for lambda expressions in Java?\n
- What are the rules for the body of lambda expression in Java?

Advertisements