

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to define a variable in C++?
To define a variable in C++, you need to use the following syntax −
Syntax
datatype variable_name;
You need to know what type of data is your variable is going to hold and what it will be called. 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
Examples of defining variables −
int my_var; float my_float; double num;
- Related Questions & Answers
- How to define global variable in a JavaScript function?
- Various ways to define a variable in JavaScript
- Define Variable Scope in JavaScript?
- How do we use enum keyword to define a variable type in C#?
- How Can we permanently define user-defined variable for a client in MySQL?
- Must you define a data type when declaring a variable in JavaScript?
- How to define a function in Python?
- How to define a method in JavaScript?
- How to define a function in JavaScript?
- How to define a structure in C#
- How to Define a Format in Perl?
- How to define a class in Arduino?
- How to define a Regular Expression in JavaScript?
- How to define a definition list in HTML?
- How to define a rectangular array in C#?
Advertisements