C++ Articles

Page 543 of 597

C++ Program Structure

Ayyan
Ayyan
Updated on 11-Feb-2020 2K+ Views

The best way to learn a programming language is by writing programs. Typically, the first program beginners write is a program called "Hello World", which simply prints "Hello World" to your computer screen. Although it is very simple, it contains all the fundamental components C++ programs have. Let's look at the code for this program −#include int main() {    std::cout

Read More

Compound Assignment Operators in C++

Govinda Sai
Govinda Sai
Updated on 11-Feb-2020 4K+ 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

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

Nitya Raut
Nitya Raut
Updated on 10-Feb-2020 426 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

How to Edit, Compile, and Execute a C++ Program?

Paul Richard
Paul Richard
Updated on 10-Feb-2020 3K+ Views

Create a new cpp file using your text editor. Enter the following in it −#include int main() {     std::cout

Read More

What does the volatile keyword mean in C++?

Priya Pallavi
Priya Pallavi
Updated on 10-Feb-2020 2K+ Views

volatile means two things −- The value of the variable may change without any code of yours changing it. Therefore whenever the compiler reads the value of the variable, it may not assume that it is the same as the last time it was read, or that it is the same as the last value stored, but it must be read again.- The act of storing a value to a volatile variable is a "side effect" which can be observed from the outside, so the compiler is not allowed to remove the act of storing a value; for example, if ...

Read More

Why do we use const qualifier in C++?

Srinivas Gorla
Srinivas Gorla
Updated on 10-Feb-2020 2K+ Views

We use the const qualifier to declare a variable as constant. That means that we cannot change the value once the variable has been initialized. Using const has a very big benefit. For example, if you have a constant value of the value of PI, you wouldn't like any part of the program to modify that value. So you should declare that as a const.Objects declared with const-qualified types may be placed in read-only memory by the compiler, and if the address of a const object is never taken in a program, it may not be stored at all.  For ...

Read More

Count all possible position that can be reached by Modified Knight in C++

Ayush Gupta
Ayush Gupta
Updated on 10-Feb-2020 184 Views

In this tutorial, we will be discussing a program to find the number of possible positions that can be reached by Modified Knight.For this we will be provided with a 8*8 chessboard. Our task is to find the number of positions Modified Knight can capture with the given number of steps.Example#include using namespace std; //finding the positions void findSteps(int current_row, int current_column, int curr, int board_size, int steps, int* visited){    //bound checking    if (current_row >= board_size || current_row < 0       || current_column >= board_size || current_column < 0       || curr > ...

Read More

How to Install C++ Compiler on Windows?

Arushi
Arushi
Updated on 10-Feb-2020 6K+ Views

There are several alternatives for compiling C++ on windows. Let's look at 2 of them:GCCTo install GCC on Windows you need to install MinGW. To install MinGW, go to the MinGW homepage, www.mingw.org, and follow the link to the MinGW download page. Download the latest version of the MinGW installation program which should be named MinGW-.exe.While installing MinGW, at a minimum, you must install gcc-core, gcc-g++, Binutils, and the MinGW runtime, but you may wish to install more.Add the bin subdirectory of your MinGW installation to your PATH environment variable so that you can specify these tools on the command ...

Read More

Count all possible paths between two vertices in C++

Ayush Gupta
Ayush Gupta
Updated on 10-Feb-2020 489 Views

In this tutorial, we will be discussing a program to find the number of paths between two vertices.For this we will be provided with a directed graph. Our task is to find the number of paths possible between two given vertices.Example#include using namespace std; //constructing a directed graph class Graph{    int V;    list *adj;    void countPathsUtil(int, int, bool [], int &);    public:       //constructor       Graph(int V);       void addEdge(int u, int v);       int countPaths(int s, int d); }; Graph::Graph(int V){    this->V = V;    adj ...

Read More

Count all possible N digit numbers that satisfy the given condition in C++

Ayush Gupta
Ayush Gupta
Updated on 10-Feb-2020 236 Views

In this tutorial, we will be discussing a program to find the number of possible N digit numbers that satisfy the given condition.For this we will be provided with an integer. Our task is to check which one of number having N digits followNumber + Reverse(Number) = 10N -1Example#include using namespace std; //returning the count of numbers string count_num(int N){    if (N % 2 == 1)       return 0;    string result = "9";    for (int i = 1; i

Read More
Showing 5421–5430 of 5,962 articles
« Prev 1 541 542 543 544 545 597 Next »
Advertisements