Found 7346 Articles for C++

C++ Program that will fill whole memory

George John
Updated on 30-Jul-2019 22:30:25

229 Views

In this article we will see how to fill the whole memory by writing a simple C++ program. Here the logic is very simple. We shall create new integer variables by using the dynamic memory allocation. If we create some variables again and again, it will fill the entire primary memory.In C++ to dynamically allocate a memory space we can use the new keyword.The basic syntax of the new operator is like below.pointer_var = new data_typeTo deallocate the memory space, we can use the delete keyword. The syntax isdelete pointer_varNote After running this program it may slow down the performance ... Read More

C++ Program to Print “Even” or “Odd” without using conditional statement

Chandu yadav
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to check whether a number is odd or even without using any kind of conditional statements like (=, ==).We can easily check the odd or even by using the conditional statements. We can divide the number by 2, then check whether the remainder is 0 or not. if 0, then it is even. Otherwise we can perform AND operation with the number and 1. If the answer is 0, then it is even, otherwise odd.Here no conditional statements can be used. We will see two different methods to check the odd or even.Method ... Read More

Rules for operator overloading in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

14K+ Views

In C++ it supports compile time polymorphism. The examples of compile time polymorphism are the function overloading and the operator overloading.There are some rules for the operator overloading. These rules are like belowOnly built-in operators can be overloaded. If some operators are not present in C++, we cannot overload them.The arity of the operators cannot be changedThe precedence of the operators remains same.The overloaded operator cannot hold the default parameters except function call operator “()”.We cannot overload operators for built-in data types. At least one user defined data types must be there.The assignment “=”, subscript “[]”, function call “()” and ... Read More

Unordered_multimap operator= in C++

George John
Updated on 30-Jul-2019 22:30:25

48 Views

The C++ function std::unordered_multimap::operator=() assigns new contents to the unordered_multimap by replacing old ones and modifies size if necessary.Following is the declaration for std::unordered_multimap::operator=() function form std::unordered_map() header.C++11 (Syntax)unordered_multimap& operator=(const unordered_multimap& umm);Parametersumm - Another unordered_multimap object of same type.Return ValueReturns this pointer.Example Code#include #include using namespace std; int main(void) {    unordered_multimap umm1 = {       {'a', 1},       {'b', 2},       {'c', 3},       {'d', 4},       {'e', 5},    };    unordered_multimap umm2;    umm2 = umm1;    cout

Overloading stream insertion (<<) and extraction (>>) operators in C++

Chandu yadav
Updated on 30-Jul-2019 22:30:25

8K+ Views

C++ is able to input and output the built-in data types using the stream extraction operator >> and the stream insertion operator and insertion operator

Operators that cannot be overloaded in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

10K+ Views

In C++ we can overload some operators like +, -, [], -> etc. But we cannot overload any operators in it. Some of the operators cannot be overloaded. These operators are like below? “.” Member access or dot operator? “? : ” Ternary or conditional operator? “::” Scope resolution operator? “.*” Pointer to member operator? “sizeof” The object size operator? “typeid” Object type operatorThese operators cannot be overloaded because if we overload them it will make serious programming issues.For an example the sizeof operator returns the size of the object or datatype as an operand. This is evaluated by the ... Read More

Copy constructor vs assignment operator in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

The Copy constructor and the assignment operators are used to initializing one object to another object. The main difference between them is that the copy constructor creates a separate memory block for the new object. But the assignment operator does not make new memory space. It uses the reference variable to point to the previous memory block.Copy Constructor (Syntax)classname (const classname &obj) { // body of constructor }Assignment Operator (Syntax)classname Ob1, Ob2; Ob2 = Ob1;Let us see the detailed differences between Copy constructor and Assignment Operator.Copy ConstructorAssignment OperatorThe Copy constructor is basically an overloaded constructorAssignment operator is ... Read More

Type Casting operators in C++

George John
Updated on 30-Jul-2019 22:30:25

389 Views

A cast is a special operator that forces one data type to be converted into another. As an operator, a cast is unary and has the same precedence as any other unary operator.The most general cast supported by most of the C++ compilers is as follows(type) expressionWhere type is the desired data type. There are other casting operators supported by C++, they are listed below -? const_cast (expr) The const_cast operator is used to explicitly override const and/or volatile in a cast. The target type must be the same as the source type except for the alteration of its const ... Read More

Difference between "new operator" and "operator new" in C++?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

886 Views

In C++ when we want to create a new object, we have to create a memory block into the memory, then also call constructor to initialize the memory block. We can create memory element by using the new keyword. This new operator is doing two consecutive task. But the operator new just only create memory space.New KeywordThe new operator is a special type of operator, which denotes a request for memory allocation on the heap section. When sufficient memory is available, then only new operators initializes the memory to the pointer variable. When we create an object using a normal ... Read More

What is an arrow operator, `->` in C++?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

350 Views

The dot and arrow operator are both used in C++ to access the members of a class or structure. 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 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, i.e., if a is a pointer to an ... Read More

Advertisements