
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7197 Articles for C++

18K+ 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

17K+ Views
cin is an object of the input stream and is used to take input from input streams like files, console, etc. cout is an object of the output stream that is used to show output. Basically, cin is an input statement while cout is an output statement.They also use different operators. cin uses the insertion operator( >> ) while cout uses the extraction operator( >), which helps to extract the input from the cin and stores it in a variable. It automatically skips the whitespaces (spaces, tabs, newlines) until a special method like getline() is used. Syntax Here is the ... Read More

220 Views
"" Outputs a newline (in the appropriate platform-specific representation, so it generates a "\r" on Windows), but std::endl does the same and flushes the stream. Usually, you don't need to flush the stream immediately and it'll just cost you performance, so, for the most part, there's no reason to use std::endl.When you want to flush the stream manually -- e.g. because you expect your output to be made visible to the user in a timely fashion -- you should use std::endl instead of writing '' to the stream (whether as an isolated character or part of a string). Read More

20K+ 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. Example #include using namespace std; void foo(int&& a) { cout

34K+ Views
There is a big distinction between the suffix and prefix versions of ++. In this article, we will see the differences between them and will go through it's examples. Prefix version (++i) In the prefix version (i.e., ++i), the value of i first increments, and then the value of the expression becomes the new value of i. So basically it first increments and then assigns a value to the expression. Postfix version (i++) In the postfix version (i.e., i++), the value of I first increments, but the value ... Read More

4K+ Views
cout is an object of the stdout stream, while cerr is an object of the stderr stream.stdout and stderr are different streams, even though they both refer to console output by default. Redirecting (piping) one of them (e.g., program.exe >out.txt) would not affect the other. These are both provided by the library in C++. In this article, we will learn the difference between these two output streams in more detail. Character Output Stream (cout) The character output stream is used to display the data or information to the console (standard output device, basically the screen), like printing messages, results, ... Read More

310 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

990 Views
cerr and clog are both objects of the stderr(standard error) stream, which is used to display error messages or diagnostics. In this article, we will learn the difference between these two in more detail. Further, the description of the cout object is also given to get a clearer picture. Unbuffered standard error stream (cerr) The cerr is the standard error stream, which is used to output the errors. This is also an instance of the ostream (as iostream means input/output stream) class. As cerr is unbuffered, therefore it's used when we need to display the error message instantly. It doesn't ... Read More

1K+ Views
In C++, the new operator is mainly used for allocating memory on the heap, but to initialize that memory, you need to explicitly declare and provide a value to it.Here, the new operator dynamically allocates memory for a variable or object during runtime and returns a pointer to the allocated memory. Here are the following ways you can initialize memory using the new operator: For built-in types For arrays For objects new Operator in Built-in Types The built-in types are the basic data types in C++, which ... Read More

3K+ Views
The cin, cout, cerr, and clog are streams that handle standard input and output stream objects, which are defined in an header file. Standard Output Stream (std::cout) The 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). Syntax Here is the following syntax for cout in C++: cout