- 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 7346 Articles for C++
2K+ Views
Floating-point constants specify values that must have a fractional part.Floating-point constants have a "mantissa, " which specifies the value of the number, an "exponent, " which specifies the magnitude of the number, and an optional suffix that specifies the constant's type(double or float).The mantissa is specified as a sequence of digits followed by a period, followed by an optional sequence of digits representing the fractional part of the number. For example −24.25 12.00These values can also contain exponents. For example, 24.25e3 which is equivalent to 24250In C++ you can use the following code to create a floating point constant −ExampleLive ... Read More
2K+ Views
Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.In C++ you can use the following code to create an integer constant −#include using namespace std; int main() { const int x = 15; // 15 is decimal integer constant while x is a constant int. int y = 015; // 15 is octal integer constant while y is an int. return 0; }You can ... Read More
584 Views
A literal is a value that is expressed as itself. For example, the number 25 or the string "Hello World" are both literals.A constant is a data type that substitutes a literal. Constants are used when a specific, unchanging value is used various times during the program. For example, if you have a constant named PI that you'll be using at various places in your program to find the area, circumference, etc of a circle, this is a constant as you'll be reusing its value. But when you'll be declaring it as −const float PI = 3.141;The 3.141 is a ... Read More
408 Views
A literal is any notation for representing a value within the source code. They just exist in your source code and do not have any reference a value in memory. Contrast this with identifiers, which refer to a value in memory.There are several types of literals in C++. Some of the examples of literals are −"Hello" (a string)3.141 (a float/double)true (a boolean)3 (an integer)'c' (a character)Things that are not literals −bar = 0; (a statement)3*5-4 (an expression)std::cin (an identifier)
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
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; }
564 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.
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
835 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
573 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