- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34489 Articles for Programming
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Variable and constant are two commonly used mathematical concepts. Simply put, a variable is a value that is changing or that have the ability to change. A constant is a value which remains unchanged.For example, if you have a program that has a list of 10 radii and you want to calculate the area for all of these circles. To find the area of these circles, you'll write a program that will have a variable that will store the value of PI and this value will not change throughout the program. Such values can be declared as a constant.In the ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
583 Views
There are no types of constants in C++. It's just that you can declare any data type in C++ to be a constant. If a variable is declared as constant using the const keyword, you cannot reassign its value. Example#include using namespace std; int main() { const int i = 5; // Now all of these operations are illegal and // will cause an error: i = 10; i *= 2; i++; i--; //... return 0; }
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
567 Views
You can define constants in C++ by adding the const qualifier before the declaration of the variable. Example#include using namespace std; int main() { const int x = 9; x = 0; return 0; }This will define the constant variable x. But it will throw an error as we are trying to rewrite the value of a constant.
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
9K+ Views
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 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
847 Views
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 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
581 Views
Type inference or deduction refers to the automatic detection of the data type of an expression in a programming language. It is a feature present in some strongly statically typed languages. In C++, the auto keyword(added in C++ 11) is used for automatic type deduction. For example, you want to create an iterator to iterate over a vector, you can simply use auto for that purpose. Example#include #include using namespace std; int main() { vector arr(10); for(auto it = arr.begin(); it != arr.end(); it ++) { cin >> *it; } return 0; }In the ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
843 Views
Auto and decltype serve different purposes so they don't map one-to-one. auto is a keyword in C++11 and later that is used for automatic type deduction. The decltype type specifier yields the type of a specified expression. Unlike auto that deduces types based on values being assigned to the variable, decltype deduces the type from an expression passed to it. The value returned by decltype can directly be used to define another variable.auto follows the rules of template parameter deduction. You can read more about these rule at http://en.cppreference.com/w/cpp/language/template_argument_deductionWhile decltype has rules it should follow defined in the standard. Here ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
244 Views
Auto is a keyword in C++11 and later that is used for automatic type deduction. Type inference or deduction refers to the automatic detection of the data type of an expression in a programming language. It is a feature present in some strongly statically typed languages. For example, you want to create an iterator to iterate over a vector, you can simply use auto for that purpose. example#include #include using namespace std; int main() { vector arr(10); for(auto it = arr.begin(); it != arr.end(); it ++) { cin >> *it; } return 0; }In ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
129 Views
You can initialize a variable using the assignment operator or use its constructor when initializing it. For example,int i = 0; MyClass instance(1, "Hello");It will be automatically initialized ifIt's a class/struct instance in which the default constructor initializes all primitive types; like MyClass instance; You use array initializer syntax, e.g. int a[10] = {} (all zeroed) or int a[10] = {1,2}; (all zeroed except the first two items: a[0] == 1 and a[1] == 2) It is a global/extern variable It is defined static
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
912 Views
Type inference or deduction refers to the automatic detection of the data type of an expression in a programming language. It is a feature present in some strongly statically typed languages. In C++, the auto keyword(added in C++ 11) is used for automatic type deduction. For example, you want to create an iterator to iterate over a vector, you can simply use auto for that purpose. Example#include #include using namespace std; int main() { vector arr(10); for(auto it = arr.begin(); it != arr.end(); it ++) { cin >> *it; } return 0; ... Read More