Found 7346 Articles for C++

Basics of C++ Programming Language?

Kumar Varma
Updated on 11-Feb-2020 05:19:52

484 Views

C++ is a programming language developed by Bjarne Stroustrup in 1979 at Bell Labs. C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. It is a superset of C, and that virtually any legal C program is a legal C++ program. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. It is a language that is −Statically typed − A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time.Compiled − A compiled ... 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 the difference between cin and cout streams in c++?

Akshaya Akki
Updated on 11-Feb-2020 05:03:02

15K+ 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(

Comparison between endl and in C++

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

137 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

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

What is the difference between cerr and cout streams in c++?

Akshaya Akki
Updated on 30-Jul-2019 22:30:21

3K+ 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.Generally, stdout ought to be used for actual program output, whereas all information and error messages should be printed to stderr, in order that if the user redirects output to a file, information messages are still printed on the screen and not to the output file.

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

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

205 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

What is the difference between cerr and clog streams in c++?

Fendadis John
Updated on 30-Jul-2019 22:30:21

603 Views

cerr and clog are both objects of the stderr stream. Following are the differences between them. You can also read about the cout object to get a clearer picture.Un-buffered standard error stream (cerr)cerr is the standard error stream which is used to output the errors. This is also an instance of theostream class. As cerr is un-buffered therefore it's used when we need to display the error message instantly. It doesn't have any buffer to store the error message and display later.Buffered standard error stream (clog)This is also an instance of ostream class and used to display errors but unlike ... Read More

Advertisements