Found 7346 Articles for C++

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

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

804 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 are cin, cout and cerr streams in C++?

Jai Janardhan
Updated on 11-Feb-2020 04:52:35

2K+ Views

cin, cout, cerr, and clog are streams that handle standard inputs and standard outputs. These are stream objects defined in iostream header file.std::cin is an object of class istream that represents the standard input stream oriented to narrow characters (of type char). It corresponds to the C stream stdin. The standard input stream is a source of characters determined by the environment. It is generally assumed to be input from an external source, such as the keyboard or a file.std::cout is an object of class ostream that represents the standard output stream oriented to narrow characters (of type char). It corresponds ... 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

318 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

What is C++ Standard Error Stream (cerr)?

Arushi
Updated on 10-Feb-2020 13:41:41

4K+ Views

std::cerr is an object of class ostream that represents the standard error stream oriented to narrow characters (of type char). It corresponds to the C stream stderr. The standard error stream is a destination of characters determined by the environment. This destination may be shared by more than one standard object (such as cout or clog).As an object of class ostream, characters can be written to it either as formatted data using the insertion operator (operator

Standard Input Stream (cin) in C++

Manikanth Mani
Updated on 10-Feb-2020 13:39:48

5K+ Views

std::cin is an object of class istream that represents the standard input stream oriented to narrow characters (of type char). It corresponds to the C stream stdin. The standard input stream is a source of characters determined by the environment. It is generally assumed to be input from an external source, such as the keyboard or a file.As an object of class istream, characters can be retrieved either as formatted data using the extraction operator (operator>>) or as unformatted data, using member functions such as read. The object is declared in header with external linkage and static duration: it ... Read More

What is the ?-->? operator in C++?

Nitya Raut
Updated on 10-Feb-2020 13:37:58

255 Views

There is no such operator in C++. Sometimes, we need to create wrapper types. For example, types like unique_ptr, shared_ptr, optional and similar. Usually, these types have an accessor member function called .get but they also provide the operator→ to support direct access to the contained value similarly to what ordinary pointers do.The problem is that sometimes we have a few of these types nested into each other. This means that we need to call .get multiple times or to have a lot of dereference operators until we reach the value.Something like this −wrapper wp; wp.get().get().length(); wp.get()->length();This can be a ... Read More

What is C++ Standard Output Stream (cout)?

Rishi Raj
Updated on 10-Feb-2020 13:34:36

6K+ Views

std::cout is an object of class ostream that represents the standard output stream oriented to narrow characters (of type char). It corresponds to the C stream stdout. The standard output stream is the default destination of characters determined by the environment. This destination may be shared with more standard objects (such as cerr or clog).As an object of class ostream, characters can be written to it either as formatted data using the insertion operator (operator

C++ Standard Library Header Files

Moumita
Updated on 18-Jun-2020 13:57:27

1K+ Views

The C++ standard library comprises of different types of libraries. The following is a list of all these Types with the libraries under them.Utilities library − General purpose utilities like program control, dynamic memory allocation, random numbers, sort and search  −Functions and macro constants for signal management(eg SIGINT, etc)  −Macro (and function) that saves (and jumps) to an execution context − Handling of variable length argument lists − Runtime type information utilities − class template of std::bitset − Function objects, Function invocations, Bind operations and Reference wrappers − Various utility components − C-style time/date utilites − standard macros and typedefs(since ... Read More

Operators Precedence in C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:21

15K+ Views

Operator precedence determines the grouping of terms in an expression. The associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator:For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.Here, operators with the highest precedence appear ... Read More

Advertisements