C++ text Flashcards

(23 cards)

1
Q

What is the purpose of the main() function in C++?

A

It’s the entry point of every C++ program where execution begins.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you declare an integer variable in C++?

A

int x = 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic data types in C++?

A

int, float, double, char, bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you write a single-line comment in C++?

A

Use // before the comment text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you write a multi-line comment in C++?

A

Use /* comment */ syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does #include <iostream> do?</iostream>

A

It allows input/output operations using cin and cout

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you print text to the console in C++?

A

cout «_space;“Hello, world!”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you take input from the user in C++?

A

cin»_space; variable;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a constant in C++?

A

A value that cannot be changed after initialization, declared using const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you declare a constant integer in C++?

A

const int MAX = 100;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a conditional statement?

A

A way to make decisions in code using if, else if, and else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the syntax of an if statement in C++?

A

if (condition) { /* code */ }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three types of loops in C++?

A

for, while, do-while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you write a for loop in C++?

A

for (int i = 0; i < 5; i++) { /* code */ }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you write a while loop in C++?

A

while (condition) { /* code */ }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you write a do-while loop in C++?

A

do { /* code */ } while (condition);

17
Q

What is a function in C++?

A

A reusable block of code that performs a specific task

18
Q

How do you define a function in C++?

A

returnType functionName(parameters) { /* code */ }

19
Q

What is the difference between int and float?

A

int stores whole numbers, float stores decimal numbers

20
Q

What is a boolean value in C++?

A

A value that is either true or false

21
Q

What is the modulus operator (%) used for?

A

It returns the remainder of a division

22
Q

What is the scope of a variable?

A

The region of code where the variable is accessible

23
Q

What is the purpose of return in a function?

A

It sends a value back to the caller of the function