- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the rules to declare 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 (a 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
You can declare variables using the syntax −
int my_var; float my_float; ...
- What are the basic rules for defining variables in C++?
- What are the basic scoping rules for python variables?
- How to declare variables in C#?
- What are the scope rules to functions in C programming?
- What are the rules for naming classes in C#?
- What are the rules for calling the superclass constructor C++?
- What are local variables in C++?
- What are global variables in C++?
- What are local variables and global variables in C++?
- What are variables and types of variables in C++?
- How to declare global variables in Android?