Found 27104 Articles for Server Side Programming

Explicit type casting operator in C++

Daniol Thomas
Updated on 11-Feb-2020 05:33:34

491 Views

A type cast provides a method for explicit conversion of the type of an object in a specific situation. It can be used as a unary expression −( type-name ) cast-expressionThe compiler treats cast-expression as type type-name after a typecast has been made. Casts are used to convert objects of any scalar kind to or from the other scalar type. Explicit type casts are constrained by the same rules that determine the effects of implicit conversions. Additional restraints on casts could result from the actual sizes or representation of specific types example#include using namespace std; int main() {    float x ... Read More

Conditional ternary operator ( ?: ) in C++

Abhinanda Shri
Updated on 11-Feb-2020 05:30:35

489 Views

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows −The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.If the first operand evaluates to true (1), the second operand is evaluated.If the first operand evaluates to false (0), the third operand is evaluated.The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression. The evaluation of the conditional operator ... Read More

Compound Assignment Operators in C++

Govinda Sai
Updated on 11-Feb-2020 05:10:31

3K+ Views

The compound assignment operators are specified in the form e1 op= e2, where e1 is a modifiable l-value not of const type and e2 is one of the following −An arithmetic typeA pointer, if op is + or –The e1 op= e2 form behaves as e1 = e1 op e2, but e1 is evaluated only once.The following are the compound assignment operators in C++ −OperatorsDescription*=Multiply the value of the first operand by the value of the second operand; store the result in the object specified by the first operand./=Divide the value of the first operand by the value of the ... Read More

Simple Arithmetic Operators Example Program In C++

Ramu Prasad
Updated on 11-Feb-2020 05:07:26

13K+ Views

C++ has 5 basic arithmetic operators. They are −Addition(+)Subtraction(-)Division(/)Multiplication(*)Modulo(%)These operators can operate on any arithmetic operations in C++. Let's have a look at an example −Example#include using namespace std; main() {    int a = 21;    int b = 10;    int c ;    c = a + b;    cout

What is double address operator(&&) in C++?

Sravani S
Updated on 11-Feb-2020 05:00:36

16K+ Views

&& is a new reference operator defined in the C++11 standard. int&& a means "a" is an r-value reference. && is normally only used to declare a parameter of a function. And it only takes an r-value expression.Simply put, an r-value is a value that doesn't have a memory address. E.g. the number 6, and character 'v' are both r-values. int a, a is an l-value, however (a+2) is an r-value. examplevoid foo(int&& a) {    //Some magical code... } int main() {    int b;    foo(b);       //Error. An rValue reference cannot be pointed to a lValue. ... Read More

What is the difference between ++i and i++ in C++?

V Jyothi
Updated on 08-Sep-2023 23:00:20

32K+ Views

There is a big distinction between the suffix and prefix versions of ++.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, 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.                               ... Read More

When should you use 'friend' in C++?

Krantik Chavan
Updated on 11-Feb-2020 04:58:06

203 Views

A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows −class Box {    double ... Read More

How to initialize memory with a new operator in C++?

Nishtha Thakur
Updated on 19-Jun-2020 05:22:14

801 Views

The new operator in C++ is defined for allocating memory and not initializing. If you want to allocate an array of type int with the new operator, and you want to initialize them all to the default value(ie 0 in case of ints), you can use the following syntax −Syntaxnew int[10]();Note that you simply must use the empty parentheses - you can't, for example, use (0) or the other expression that is why this is only helpful for default initialization.There are other methods of initializing the same memory using fill_n, memset, etc which you can use to initialize objects to ... Read More

What is the difference between the dot (.) operator and -> in C++?

Smita Kapse
Updated on 11-Feb-2020 04:49:15

2K+ Views

The dot and arrow operator are both used in C++ to access the members of a class. They are just used in different scenarios. In C++, types declared as class, struct, or union are considered "of class type". So the following refers to all three of them.a.b is only used if b is a member of the object (or reference[1] to an object) a. So for a.b, a will always be an actual object (or a reference to an object) of a class.a→b is essentially a shorthand notation for (*a).b, ie, if a is a pointer to an object, then ... Read More

What are the basic rules and idioms for operator overloading in C++?

Anvi Jain
Updated on 19-Jun-2020 05:21:04

317 Views

When it comes to operator overloading in C++, there are 3 basic rules you should follow. like all such rules, there are so exceptions. These 3 rules are −1.  Whenever the meaning of an operator is not obviously clear and undisputed, it should not be overloaded. Instead, provide a function with a well-chosen name. Basically, the first and foremost rule for overloading operators, at its very heart, says:Don’t do it.That might seem strange, but there are only a few cases where operator overloading is appropriate. The reason is, it is hard to understand the semantics behind the application of an ... Read More

Advertisements