Found 34489 Articles for Programming

What does a semicolon do after a C++ class name?

Naveen Singh
Updated on 11-Feb-2020 07:51:53

306 Views

If you have statements like −Class Person;This is a forward declaration. It lets the following code know that there is are classes with the name Person. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes.

What is the difference between a definition and a declaration in C++?

Naveen Singh
Updated on 30-Jul-2019 22:30:21

1K+ Views

In C++, declaration and definition are often confused. A declaration means (in C) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of the declaration. The Definition on the other hand means that in additions to all the things that declaration does, space is additionally reserved in memory. You can say "DEFINITION = DECLARATION + SPACE RESERVATION". Following are examples of declarations − extern int ... Read More

How to define a variable in C++?

Naveen Singh
Updated on 11-Feb-2020 07:50:55

160 Views

To define a variable in  C++, you need to use the following syntax −Syntaxdatatype 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 ... Read More

How to declare a variable in C++?

Naveen Singh
Updated on 11-Feb-2020 08:01:15

460 Views

In C++, declaration and definition are often confused. A declaration means (in C) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of a declaration.The Definition on the other hand means that in additions to all the things that declaration does, space is additionally reserved in memory. You can say "DEFINITION = DECLARATION + SPACE RESERVATION".Following are examples of declarations −extern int a;       ... Read More

How to define an enumerated type (enum) in C++?

Naveen Singh
Updated on 11-Feb-2020 07:47:54

282 Views

An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration. For example, if you are creating an application that has a fixed number of types for some variable. For example, let's say gender, it can be of three types male, female and others. You can define and use an enum like −#include using namespace std; enum Gender {MALE, FEMALE, OTHERS}; int main() {    Gender gen = Gender.FEMALE;    return 0; }By default, the value ... Read More

What are equality operators in C++?

Naveen Singh
Updated on 11-Feb-2020 07:46:53

965 Views

The equality operators in C++ are is equal to(==) and is not equal to(!=). They do the task as they are named. The binary equality operators compare their operands for strict equality or inequality. The equality operators, equal to (==) and not equal to (!=), have lower precedence than the relational operators, but they behave similarly. The result type for these operators is bool.The equal-to operator (==) returns true (1) if both operands have the same value; otherwise, it returns false (0). The not-equal-to operator (!=) returns true if the operands do not have the same value; otherwise, it returns ... Read More

What is the difference between prefix and postfix operators in C++?

Naveen Singh
Updated on 11-Feb-2020 07:44:03

2K+ Views

In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression. In the postfix version (i.e., i++), the value of i is incremented, however, the {value|the worth} of the expression is that the original value of i. So basically it first assigns a value to expression and then increments the variable.Let's look at some code to get a better understanding −Example#include using namespace std; int main() {    int x = 3, y, z;   ... Read More

What are enumerated data types in C++?

Naveen Singh
Updated on 11-Feb-2020 07:42:19

699 Views

An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration. For example, if you are creating an application that has a fixed number of types for some variable. For example, let's say gender, it can be of three types male, female and others. You can define and use an enum like −#include using namespace std; enum Gender {MALE, FEMALE, OTHERS}; int main() {    Gender gen = Gender.FEMALE;    return 0; }By default, the value ... Read More

What are postfix operators in C++?

Naveen Singh
Updated on 11-Feb-2020 07:41:18

4K+ Views

Postfix operators are unary operators that work on a single variable which can be used to increment or decrement a value by 1(unless overloaded). There are 2 postfix operators in C++, ++ and --.In the postfix notation (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i. So basically it first assigns a value to expression and then increments the variable. For example, Example#include using namespace std; int main() {    int j = 0, i = 10;    // If we assign j to be i++, j ... Read More

What are shift operators in C++?

Naveen Singh
Updated on 11-Feb-2020 07:39:27

6K+ Views

The bitwise shift operators are the right-shift operator (>>), which moves the bits of shift_expression to the right, and the left-shift operator (

Advertisements