C++

What is the Meaning of the Word “cout” in C++

Each computer programming language has its own specific syntax and keywords which the user of that language needs to follow. Similarly, for C++ there are some specific syntax and keywords such as cout, cin, int, and many such keywords which need to be written the same all the time otherwise the C++ program won’t run.

In this article, we will specifically focus on the “cout” keyword, what is the meaning of it and how to use it.

What is the Meaning of the Word “cout” in C++?

The cout in C++ is just a keyword to display/print the output of the program on the compiler’s screen. It is common for programming languages to have a specific keyword to display the output such as print, cout, and echo. The term cout stands for “Console Output”, and it works under the std C++ library.

The basic syntax for cout in C++ is mentioned below:

cout<<"(variable or message)";

Example 1

An example code to display the string output using cout in C++ is shared below:

#include <iostream>

using namespace std;

int main() {

cout<<"Welcome to LinuxHint!";

  return 0;

}

In the output of the above C++ code, you can see that whatever is written after cout is printed as an output on the screen:

Example 2

Another example for cout is shared below:

#include <iostream>

using namespace std;

  int main() {

  int x=10;

  int y=5;

  cout<< "Sum =" << x+y;

  return 0;

}

In the output, you can see that the summation operator is applied on variables x and y and the result of it is displayed as an output.

Whenever, cout is used with ” “ (double quotes), then the entire message inside the quotes will be printed exactly to the output screen. Whereas, if the variable is used after cout with double quotes then the value of the variable or the operation performed on variables will be printed.

Conclusion

The cout is the keyword in C++ which stands for “console output” and it is used to display the output of the program onto the screen. cout works under the headers of <iostream> and namespace std, without these it won’t work. The basic syntax of cout along with examples are shared in the above-given guidelines.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.