You can display the current value of a variable by using cout. The following statements declare a variable named answer, assign it the value 42, and display that value:
When we talk about displaying a variable, we generally mean the value of the variable. To display the name of a variable, you have to put it in quotes:
Printing out a variableβs name and value can be very helpful for debugging. For example, if you have a variable totalPay that holds the total pay for a week, you could print it out like this:
As the program runs, it will print out the current value of totalPay so that we can examine the output and see what value the variable had at that point.
Recall that to output multiple values on the same line, you can either use one cout that outputs multiple values (each separated by <<) or you can use multiple cout statements. This program demonstrates two different ways to print 11:59.