Chapter 2 Flashcards
(104 cards)
What marks the beginning of a comment in C++?
//
What is the purpose of comments in C++ programs?
To explain what’s going on in the code
What is a preprocessor directive in C++?
A line that begins with # and is executed by the preprocessor
What does the #include <iostream> directive do?</iostream>
Includes the contents of the iostream header file
What is the role of the iostream header file?
Allows a C++ program to display output and read input
What does the statement ‘using namespace std;’ do?
Gives access to the names in the std namespace
What is the significance of ‘int main()’ in a C++ program?
It marks the beginning of the main function, which is the starting point of the program
What does ‘int’ represent in ‘int main()’?
Indicates that the function returns an integer value
Why is C++ considered a case-sensitive language?
It treats uppercase and lowercase letters as different characters
What is the function of the left brace ‘{‘ in C++?
Indicates the beginning of a function’s body
What is a string literal in C++?
A group of characters enclosed in “double quotation marks”
What does the statement cout << "Programming is great fun!";
do?
Displays the message on the screen
What symbol marks the end of a complete statement in C++?
;
What does ‘return 0;’ signify in a C++ program?
Indicates successful execution of the program
What does a closing brace ‘}’ denote in a C++ program?
Marks the end of a function or block
The contents of the < iostream > file are included in the program at the point the #include statement appears, which is called a ?
preprocessor directive
True or False: Every C++ program must have a function called main.
True
What is the output of the sample program?
// A simple C++ program
#include <iostream>
using namespace std;</iostream>
int main(){
cout «_space;“Programming is great fun!”;
return 0;
}
Programming is great fun!
What is the purpose of the cout object in C++?
To display information on the computer’s screen
cout stands for console output.
What is the stream insertion operator in C++?
It sends a stream of characters to cout.
«
It sends a stream of characters to cout.
What does the statement cout «_space;“Programming is great fun!”; do?
It displays the message ‘Programming is great fun!’ on the screen.
Can the stream insertion operator be used to send multiple items to cout?
Yes.
True or False: The cout object starts a new line automatically after each output.
False.
How can you instruct cout to start a new line?
Using the stream manipulator endl or the escape sequence \n.