What Will The Following Code Output? Int Number = 22; Int *var = &number; Cout << *var << Endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
1. Which one of the following options refers to a collection of programs that a computer executes?
A) Software
B) Assembler
C) Instructions
D) Source code

Ans: A
Section Ref: 1.1
Title: Which (term) refers to a collection of programs?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

2. Computers are machines that
A) Design computer programs
B) Execute programs
C) Carry out a very narrow range of tasks
D) Are imprecise and slow

Ans: B
Section Ref: 1.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What kind of machines are computers?
Difficulty: Easy

3. Computer programming is

A) The speed with which a computer operates
B) The collection of peripheral devices connected to a computer
C) The storage of data in the form of words and pictures
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The act of designing and implementing a computer program

Ans: D
Section Ref: 1.1
Title: What is computer programming?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
4. Consider the following statements regarding computers:
I. Computers can execute a large number of instructions in a fraction of a second.
II. Computer application areas mainly target the research and scientific communities.
III. The physical components of a computer constitute its hardware.
IV. Unlike humans, a computer never gets bored or exhausted on performing repetitive tasks.
Which one of the following options is correct?

A) Only III is a valid statement.
B) I and III are valid statements.
C) I, II, and III are valid statements.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) I, III, and IV are valid statements.

Ans: D
Section Ref: 1.1
Title: Which statement(s) regarding computers is(are) correct?
Difficulty: Easy

5. Consider the following statements about computer programs:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
I. Computer programs can be written by someone who has a basic knowledge of operating a computer.
II. Computer programs can complete complex tasks quickly.
III. Large and complex computer programs are generally written by a group of programmers.
IV. Computer programs are composed of extremely primitive operations.
Which one of the following options is correct?

A) II and III are correct statements.
B) I, II, III, and IV are correct statements.
C) II, III, and IV are correct statements.
D) I and IV are correct statements.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 1.1
Title: Which statement(s) regarding computer programs is(are) correct?
Difficulty: Easy

6. The Central Processing Unit is primarily responsible for

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Performing program control and data processing
B) Ensuring data persists when electrical power is turned off
C) Enabling a human user to interact with the computer
D) Interconnecting computers that are separated by distance

Ans: A
Section Ref: 1.2
Title: What is the function of a CPU?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

7. A single silicon chip made from potentially millions of transistors is called

A) A Central Processing Unit (CPU)
B) Secondary Storage
C) A Hard Disk
D) An Optical Disk (such as a DVD)

Ans: A
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 1.2
Title: What is a chip with transistors called?
Difficulty: Easy

8. An example of an output device that interfaces between computers and humans is

A) The keyboard
B) The mouse
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The speaker
D) A microphone

Ans: C
Section Ref: 1.2
Title: What is an example of an output device that interfaces between humans and computers?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
9. An example of an input device that interfaces between computers and humans is

A) The microphone
B) The monitor
C) The printer
D) The speaker

Ans: A
Section Ref: 1.2
Title: What is an example of an input device that interfaces between humans and computers?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy

10. Programs that are not running are usually stored

A) in the CPU’s memory.
B) on the computer monitor.
C) in secondary storage.
D) on a backup device that is in a different physical location from the computer.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 1.2
Title: Where are programs usually stored when they are not running?
Difficulty: Easy

11. When a program begins to run,

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) It is moved from DVD to hard disk.
B) It is moved to the CPU’s memory.
C) It is moved from the CPU’s memory to hard disk.
D) It must be connected to a computer network.

Ans: B
Section Ref: 1.2
Title: What happens when a program begins to run?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

12. Which one of the following typically provides data persistence without electricity?
I. The CPU’s memory
II. The hard disk
III. Secondary storage

A) I, II
B) I, III
C) II, III
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) I, II, III

Ans: C
Section Ref: 1.2
Title: Which storage type provides data persistence without electricity?
Difficulty: Easy

13. Consider a scenario in which you develop a C++ program on a computer that has a Pentium processor and compile the program into the corresponding machine language. What step should you take to run the same program on a computer that has a different processor?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Copy the compiled machine language instructions to the computer that has a different processor.
B) Develop the same program again on the computer that has a different processor and recompile the program.
C) Recompile the C++ program on the computer that has a different processor.
D) You cannot run the program on a computer with a different processor because C++, being a high-level programming language, is machine dependent.

Ans: C
Section Ref: 1.3
Title: What step should you take to run a C++ program on a (different) processor?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

14. High level programming languages

A) Are made up primarily of ones and zeros
B) Are independent of the underlying hardware
C) Are not standardized
D) Use syntax that is close to the underlying hardware’s instruction set

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 1.3
Title: What are the characteristics of high level programming languages?
Difficulty: Easy

15. Which one of the following translates high-level descriptions into machine code?

A) Assembler
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Linker
C) Compiler
D) Editor

Ans: C
Section Ref: 1.3
Title: Which translates high-level descriptions into machine code?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

16. Computer scientists have devised something that allows programmers to describe tasks in words that are closer to the syntax of the problems being solved. This is called

A) Embedded system
B) Machine instructions
C) High level programming language
D) Compiler

Ans: C
Section Ref: 1.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What are the tools used to describe and solve high-level problems?
Difficulty: Easy

17. Small computers that control devices like automobile engines or cellular telephones are called

A) Embedded systems
B) Compilers
C) CPUs
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Peripheral devices

Ans: A
Section Ref: 1.3
Title: What are small control devices called?
Difficulty: Easy

18. What is one of the benefits of using a high-level programming language like C++?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Its syntax is very similar to the hardware instruction set
B) No tools other than a text editor are required for programming
C) Statements in the high-level language are just like English
D) Problems solved in a high-level language are independent of the underlying computer hardware

Ans: D
Section Ref: 1.3
Title: What are the benefits of using high level languages?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

19. What name do you use for small computers that are programmed to control automobile engines and cell phones?

A) Mainframe computers
B) Mini computers
C) Embedded systems
D) Virtual systems

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Section Ref: 1.3
Title: What are small computers programmed to control engines and phones called?
Difficulty: Easy

20. An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?

A) An editor and a compiler
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) A web browser
C) Presentation tools
D) A multimedia creation package

Ans: A
Section Ref: 1.4
Title: What kinds of tools are included in an IDE?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

21. What is the difference between an editor and a compiler?

A) An editor converts program files into an executable program; a compiler allows program files to be written and stored
B) An editor allows program files to be written and stored; a compiler produces an organized list of files
C) An editor allows program files to be written and stored; a compiler produces an indexed database of terms and keywords
D) An editor allows program files to be written and stored; a compile converts program files into an executable program

Ans: D
Section Ref: 1.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the difference between an editor and a compiler?
Difficulty: Easy

22. Suppose you define a C++ symbol MadCitie and another symbol Madcitie. What can be said about these two symbols?

A) Since C++ is case-sensitive, these are considered to be completely distinct
B) Because “citie” is misspelled, the C++ compiler will reject it
C) Since these C++ symbols both have the same letters, they are considered to be the same
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) They are the correct length because all C++ symbols must have exactly eight characters.

Ans: A
Section Ref: 1.4
Title: What are some of the rules for defining and understanding variable names in C++?
Difficulty: Easy

23. What statements about the integrated development environment (IDE) are true?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
I. You may run an executable program even after exiting the IDE
II. The IDE contains a program called the linker, which is required to build an executable program
III. Translating C++ source code into machine code is not enough to actually run the program

A) I, II
B) I, III
C) II, III
D) I, II, III

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 1.4
Title: What are the steps in building an executable file in C++?
Difficulty: Easy

24. Consider the following statements about folders and your integrated development environment (IDE):
I. Hierarchical folders help to organize a project
II. Folders are a way to visualize the layout of a file system
III. Folders make it impossible to lose or accidentally delete a file
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Only I is correct
B) I, II, and III are correct
C) Only I and II are correct
D) Only III is correct

Ans: C
Section Ref: 1.4
Title: How is your integrated development environment organized?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

25. Which of the following statements regarding backup strategies for C++ files are true?
I. You should back up your projects often to prevent loss of valuable work.
II. You should check your backups only in case of loss of data.
III. You should pay attention to the backup direction.

A) I, II
B) I, III
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) II, III
D) I, II, III

Ans: B
Section Ref: 1.4
Title: Which statement regarding backup strategies for C++ files is correct?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
26. Which one of the following statements is true?

A) The semicolon terminates statements in C++
B) The double quote character cannot appear within a character string in C++
C) The tab character is the only way to produce “whitespace” in a C++ program
D) The single quote character means the same thing as the double quote character in C++

Ans: A
Section Ref: 1.5
Title: Which statements are true about C++ syntax?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy

27. Characters that are grouped together between double quotes (quotation marks) in C++ are called

A) keywords
B) syntax
C) symbols
D) strings
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Section Ref: 1.5
Title: What is the term for characters grouped together and enclosed with quotes in C++?
Difficulty: Easy

28. One way to include a literal special character, such as the double quote, inside a character string, is to use

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) an escape sequence
B) the dollar sign ($)
C) the endl keyword
D) the single quote for the character string

Ans: A
Section Ref: Special Topic 1.1
Title: How are special characters designated and represented in C++?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

29. The two lines of code below both produce the same output. Why?
cout << "Hello" << " Goodbye";
cout << "Hello" << " Goodbye";

A) Since there are no numerical / arithmetic operators, the spaces don’t matter.
B) In fact, the two statements do not produce the same output.
C) Spacing between symbols in C++ doesn’t affect statements.
D) Because there are no escape characters.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 1.5
Title: Why do the example lines of code behave the way they do (understanding whitespace)?
Difficulty: Easy

30. What is the output from this code snippet?
cout << "The sum is " << "8 + 6";
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The sum is 14
B) The sum is 48
C) The sum is 2
D) The sum is 8 + 6

Ans: D
Section Ref: 1.5
Title: What is the output from this code? (arithmetic statements versus character strings)
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

31. Which of the following statements should you include in a C++ program that performs an input or output operation?
I. using namespace std;
II. #include
III. int main()

A) II only
B) I and II only
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) II and III only
D) I, II, and III

Ans: D
Section Ref: 1.5
Title: Which statements should you include in program with input/output operations?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
32. What is the output of the following code snippet?
#include
using namespace std;

int main()
{
cout << "Goodbye" << endl << "Come again" << endl;
return 0;
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Goodbye Come again
B) Goodbye
Come again
C) Goodbye
Come
again
D) No output due to compilation errors

Ans: B
Section Ref: 1.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of code snippet (using cout and endl)?
Difficulty: Easy

33. Which one of the following code snippets compiles without errors and displays the output “hello” on the screen?

A) #include
using namespace std;
int main();
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << hello << endl;
return 0;
}
B) #include
using namespace std;
int main();
{
cout << 'hello' << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
C) #include
using namespace std;
int main()
{
cout << "hello" << endl;
return 0;
}
D) #include
using namespace std;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
cout << "hello" << "endl";
return 0;
}

Ans: C
Section Ref: 1.5
Title: Which snippet compiles without errors and displays “hello”?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

34. Which one of the given code snippet represents the correct way to print the following output?
HI
“HELLO”
A) #include
using namespace std;
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << HI << endl << "HELLO" << endl;
return 0;
}
B) #include
using namespace std;
int main()
{
cout << "HI << endl << HELLO";
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) #include
using namespace std;
int main()
{
cout << 'HI' << endl << '"HELLO"';
return 0;
}
D) #include
using namespace std;
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << "HI" << endl << ""HELLO"" << endl;
return 0;
}

Ans: D
Section Ref: 1.5
Title: Which snippet correctly prints (output on two lines)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

35. What is the output of the following code snippet?
#include
using namespace std;

int main()
{
cout << 2 * 2 << 6;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) 2 * 26
B) 226
C) 46
D) 4 6
Ans: C
Section Ref: 1.5
Title: TB 1.14 What is output of snippet (with expressions sent to cout)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

36. Which of the following statements is valid with respect to the usage of the endl symbol?

I. The endl symbol denotes the end of line marker.
II. When the end of line marker is sent out to cout, the cursor is moved to the first column in the next screen row.
III. It is a good practice to end all lines of output with an end of line marker.
.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) I only.
B) II only,
C) I, II, III only
D) I and III only.

Ans: C
Section Ref: 1.5
Title: Which statement is true about the usage of endl?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

37. Which of the following symbols is used to terminate a C++ program statement?
A) Colon
B) Semicolon
C) Single quote
D) Period

Ans: B
Section Ref: 1.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which symbol is used to terminate a C++ program statement?
Difficulty: Easy

38. Which of the following statements is valid with respect to the usage of semicolon in C++?

A) A semicolon is used to denote the end of a statement.
B) A semicolon is used to terminate the #include statement.
C) You cannot use a semicolon to terminate the “using namespace” statement.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) You cannot put a semicolon within double quotation marks.

Ans: A
Section Ref: 1.5
Title: Which statement is true about semicolon usage?
Difficulty: Medium

39. Which of the following statements are valid with respect to the main function in C++?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The opening and closing parentheses after the function name main are optional.
B) A semicolon is required after the declaration int main()
C) A semicolon is required after the closing curly braces in the main function.
D) Every executable C++ program has a main function.

Ans: D
Section Ref: 1.5
Title: Which statement is true about the main function?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

40. What is the output of the following code snippet?
#include
using namespace std;

int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "cout << endl prints out a new line to " << endl
<< "the standard output stream" << endl;
return 0;
}

A) The code snippet gives a compilation error because the cout statement is inside the quotation marks
B) cout prints out a new line to
the standard output stream
C) cout << endl prints out a new line to
the standard output stream
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) prints out a new line to
the standard output stream

Ans: C
Section Ref: 1.5
Title: What is the output of snippet (with complex cout statement)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

41. Which of the given cout statements generates the following output?
///”\

A) cout << "///"\" << endl;
B) cout << "///"\\\" << endl;
C) cout << "//////""\\\" endl;
D) cout << ///"\ << endl;

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 1.5
Title: Which cout statement generates this output?
Difficulty: Hard

42. Which of the following statements enables the use of input and output operations in a C++ program?

A) using namespace std;
B) #include
C) int main(int num, double new_num)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) return 0;

Ans: B
Section Ref: 1.5
Title: Which statements enables the use of input/output operations?
Difficulty: Easy

43. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
using namespace std;
int main()
{
cout << "Hello" << endl << "Good Day!" << endl;
return 0;
}

A) Hello Good Day!
B) Hello
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Good Day!
C) Hello
Good
Day!
D) No output due to compilation errors

Ans: B
Section Ref: 1.5
Title: What is output of snippet (with cout and endl)?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

44. Which one of the following code snippets compiles without errors and displays the output “Hello world” on the screen?

A) #include
using namespace std;
int main();
{
cout << Hello world << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}

B) #include
using namespace std;
int main();
{
cout << 'Hello world' << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

C) #include
using namespace std;
int main()
{
cout << "Hello world" << endl;
return 0;
}

D) #include
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
using namespace std;
int main()
{
cout << "Hello world" << "endl";
return 0;
}

Ans: C
Section Ref: 1.5
Title: Which snippet compiles without errors and displays “Hello world”?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy

45. Which one of the given code snippets represents the correct way to print the following output?
GOOD MORNING
“AMERICA”
A) #include
using namespace std;
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << GOOD MORNING << endl << "AMERICA" << endl;
return 0;
}
B) #include
using namespace std;
int main()
{
cout << "GOOD MORNING << endl << AMERICA";
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
C) #include
using namespace std;
int main()
{
cout << 'GOOD MORNING' << endl << '"AMERICA"';
return 0;
}
D) #include
using namespace std;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
cout << "GOOD MORNING" << endl << ""AMERICA"" << endl;
return 0;
}

Ans: D
Section Ref: 1.5
Title: Which snippet correctly prints (output on two lines)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

46. What is the output of the following code snippet?
#include
using namespace std;

int main()
{
cout << 4 * 4 << 12;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}

A) 4 * 412
B) 4412
C) 1612
D) 28

Ans: C
Section Ref: 1.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of snippet (with expressions sent to cout)?
Difficulty: Medium

47. What is the output of the following code snippet?
#include
using namespace std;

int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << ""cout << endl" prints out a new line to " << endl;
cout << "the standard output stream" << endl;
return 0;
}

A) The code snippet gives a compilation error because the cout statement is inside the quotation marks
B) cout prints out a new line to
the standard output stream
C) cout << endl prints out a new line to
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
the standard output stream
D) “cout << endl" prints out a new line to
the standard output stream

Ans: D
Section Ref: 1.5
Title: What is the output of snippet (with complex cout statement)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
48. Which of the given cout statements generates the following output?
\”///

A) cout << "\"///" << endl;
B) cout << "\\\"///" << endl;
C) cout << "\\\""//////" endl;
D) cout << \"/// << endl;

Ans: B
Section Ref: 1.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which cout statement generates this output?
Difficulty: Hard

49. What kind of error is it when your program has a syntax error?

A) Compile-time error
B) Logic error
C) Run-time error
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Exception

Ans: A
Section Ref: 1.6
Title: Which kind of error is it when programs do not compile?
Difficulty: Easy

50. When a compiler finds a syntax error in a program, what happens?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The compiler goes ahead and produces an executable program but leaves out the statement where there was an error.
B) The compiler stops immediately.
C) The compiler requests input from the user before it will continue.
D) The compiler continues and may report about other errors but does not produce an executable file.

Ans: D
Section Ref: 1.6
Title: What happens when the compiler finds a syntax error?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

51. What kind of error is created by the following code snippet?
coutt << "Hello, World!" << endl;

A) No error: the code is correct
B) Logic error: the program will run until it comes to this statement
C) Syntax error: the program will not compile
D) Exception: the statement will generate an exception
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 1.6
Title: What kind of error is created by the code snippet?
Difficulty: Easy

52. What kind of error is created by the following code snippet?
cout << "The sum of 8 and 12 is " << 8 * 12 << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) No error: the code is correct
B) Logic error: the program does not produce the desired result
C) Syntax error: the code will not compile
D) Exception: the statement will generate an exception

Ans: B
Section Ref: 1.6
Title:What kind of error is created by the code snippet?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

53. What is a logic error?

A) An error that occurs when a program is running because, for example, the wrong operator was used.
B) An error in a statement that does not conform to the syntax of the programming language.
C) An error in the hardware from overheating.
D) An error introduced by the compiler when it guesses at how to fix a syntax error
.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Section Ref: 1.6
Title: What is the definition of a logic error?
Difficulty: Easy

54. How do programmers find exceptions and run-time errors?

A) Using the compiler
B) Testing by running the program with a variety of input values
C) Carefully reading over the program code
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Re-compiling using different symbols

Ans: B
Section Ref: 1.6
Title: How do programmers find exceptions and run-time errors?
Difficulty: Easy

55. The programmer, not the compiler, is responsible for testing a program to identify
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Syntax errors
B) Compile-time errors
C) Run-time errors
D) Undefined symbols

Ans: C
Section Ref: 1.6
Title: Who is responsible for what (programmer vs. compiler)?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

56. Which one of the following errors represents a part of a program that is incorrect according to the rules of the programming language?

A) Syntax errors
B) Run-time errors
C) Logic errors
D) Out-of-memory errors

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Section Ref: 1.6
Title: Which kind of error violates rules of the programming language?
Difficulty: Easy

57. The following code snippet is written to calculate the miles per gallon of two cars and print out both values.
#include
using namespace std;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
int miles1 = 420;
int miles2 = 500;
int gallons1 = 10;
int gallons2 = 15;

cout << miles1 / gallons1 << endl;
cout << miles1 / gallons2 << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
Based on the given code snippet, identify the correct statement:

A) The output is correct, and there are no errors.
B) The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a logic error.
C) The mileage of the second car is calculated correctly, but the mileage of the first car is incorrect due to a logic error.
D) The mileage of both cars is incorrect due to a logic error.

Ans: B
Section Ref: 1.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which is true about this snippet that calculates and prints mpg?
Difficulty: Hard

58. What is the error in the following code snippet, which is used for calculating the average score for a student in three subjects?
#include

int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int subject1 = 75;
int subject2 = 65;
int subject3 = 70;

int average = subject1 + subject2 + subject3 / 3;

cout << "The average is " << average;

return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The code snippet has a syntax error from an incorrect use of arithmetic operators.
B) The code snippet has a logic error.
C) The code snippet uses variable names that are not allowed in C++.
D) There is no error; the code snippet is completely accurate.

Ans: B
Section Ref: 1.7
Title: Is there an error in snippet that calculates average score?
Difficulty: Hard
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

59. Who or what is responsible for inspecting and testing the program to guard against logic errors?

A) Programmer
B) Linker
C) Compiler
D) End-user

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Section Ref: 1.7
Title: Who/what is responsible for … guarding against logic errors?
Difficulty: Easy

60. While developing a program, the programmer adds the discount amount to the total payable instead of reducing the discount amount from the total. What type of an error does this denote?

A) A syntax error
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) A logic error
C) A human error
D) A compilation error

Ans: B
Section Ref: 1.7
Title: What type of error is (adding instead of subtracting)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

61. What type of error can you identify in the following code snippet?
#include

int main
{
int a = 10;
int b = 20;
int c = a + b;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) A logic error.
B) A syntax error.
C) A run-time error.
D) No errors; the code snippet is completely accurate.

Ans: B
Section Ref: 1.7
Title: What type of error is in this snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

62. Which one of the following statements is true about a C++ compiler?

A) It translates the object code into the source code.
B) It translates the library code into the machine code.
C) It translates the source code into the machine code.
D) It translates the machine code into the source code.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 1.8
Title: Which statement is true about a C++ compiler?
Difficulty: Easy

63. Which one of the following programs combines the machine code with the library code to build an executable file?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Assembler
B) Linker
C) Editor
D) Compiler

Ans: B
Section Ref: 1.8
Title: Which program combines machine code with library code to build an executable file?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

64. What is the purpose of the following algorithm?
num = 0
Repeat the following steps 10 times
input var1
if var1 > num then
num = var1
end of if
end of repeat
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
print num

A) To find the highest among 10 numbers
B) To print out the 10 numbers
C) To find the smallest among 10 numbers
D) To search for a particular number among 10 numbers

Ans: A
Section Ref: 1.9
Title: What is the purpose of this algorithm?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

65. Consider a situation where you are buying books online. The bookseller charges $19.95 as the price per book and $4.95 as the handling cost for up to three books. For every book purchased in addition to three books, there is a handling charge of $1.50. In addition, there is a 7% tax on the cost of the books but not on the handling charges. Assuming that num_books represents the number of books you are purchasing, which of the following is the correct algorithm for calculating the total cost of the books that you are purchasing?

A) Total charge for the books = 4.95 * num_books
Tax on the books = num_books * .7
if (books <= 3) then Handling charges = 4.95
else Handling charges = 1.50 * num_books
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Total cost of order = total charge for books + tax + handling charges
B) Total charge for the books = 4.95 * num_books
Tax on the books = num_books * .07
if (books <= 3) then Handling charges = 4.95
else Handling charges = 1.50 * num_books
Total cost of order = total charge for books + tax + handling charges
C) Total charge for the books = 4.95 * num_books
Tax on the books = num_books * .07
if (books < 3) then Handling charges = 4.95
else Handling charges = 4.95 + 1.50 * (num_books – 3)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Total cost of order = total charge for books + tax + handling charges
D) Total charge for the books = 4.95 * num_books
Tax on the books = num_books * .07
if (books <= 3) then Handling charges = 4.95
else Handling charges = 4.95 + 1.50 * (num_books – 3)
Total cost of order = total charge for books + tax + handling charges

Ans: D
Section Ref: 1.9
Title: Which is the correct algorithm for calculating total cost with tax/shipping?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard

66. Consider a situation where you are planning on purchasing a new cell phone. You are considering two cell phones. These cell phones have different purchase prices. Each mobile service provider charges a different rate for each minute that the cell phone is used. To determine which cell phone is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cell phone. What are all the inputs needed for this algorithm?

A) The cost of each cell phone and the rate for each minute for each cell phone
B) The cost of each cell phone and the number of minutes provided with each cell phone
C) The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes provided with each cell phone
D) The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Section Ref: 1.9
Title: Which inputs do you need to calculate cost of purchasing/using cell phone?
Difficulty: Medium

67. Which one of the following methodologies is a sequence of precise steps formulated in English for solving a problem?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Flowcharts
B) Pseudocode
C) Algorithms
D) Terminations

Ans: B
Section Ref: 1.7
Title: Which methodology is an informal description of steps for solving a problem?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

68. Consider a situation where you are assigned to develop an algorithm to calculate the total cost of a purchase order that contains several items. The cost of each item and the tax rate is known. The standard shipping charge for the entire order is $4.95, and the special delivery charge is $19.95. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?

A) For each item on the purchase order:
Order cost = order cost + item cost
Total purchase order cost = order cost + tax rate + 4.95
B) For each item on the purchase order:
Order cost = order cost + item cost
If standard shipping
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Shipping cost = 4.95
Else
Shipping cost = 19.95
Total purchase order cost = order cost * tax rate + shipping cost
C) If standard shipping
Shipping cost = 4.95
Else
Shipping cost = 19.95
For each item on the purchase order:
Order cost = order cost + item cost + shipping cost
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Total purchase order cost = order cost * tax rate
D) If special delivery
Shipping cost = 4.95
Else
Shipping cost = 19.95
For each item on the purchase order:
Order cost = order cost + item cost
Total purchase order cost = order cost * tax rate + shipping cost

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 1.9
Title: Which is the correct pseudocode for algorithm to calculate total cost?
Difficulty: Medium

69. Consider the given scenario for describing an algorithm using pseudocode.
UML Supermarket has different ways of awarding discounts to its customers for each purchase they make. A 10% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options.
I. The discount percentage
II. The total value of the purchase
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
III. The loyalty-discount amount
IV. The customer card number
V. The amount payable after discount

A) I, II, and III
B) I and III
C) II, IV, and V
D) II and IV

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 1.9
Title: What are the inputs required to solve this problem?
Difficulty: Hard

70. Evaluate the given pseudocode to calculate the payment (pmt) with the following test values:
The total number of hours worked (working_hours) = 50
The rate paid for hourly work (rate) = 10
input working_hours
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
input rate
pmt = working_hours * rate
if working_hours > 45 then
extra_hours = working_hours – 45
extra_pmt = extra_hours * rate * 2
pmt = pmt + extra_pmt
end of if
output pmt

A) 400
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 500
C) 600
D) 1,000

Ans: C
Section Ref: 1.9
Title: Evaluate this pseudocode with these test values.
Difficulty: Hard

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

71. The following code snippet is written to calculate the kilometers per liter of two cars and print out both values.
#include
using namespace std;
int main()
{
int km1 = 600;
int km2 = 800;
int lit1 = 15;
int lit2 = 20;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

cout << km1 / lit2 << endl;
cout << km2 / lit2 << endl;
return 0;
}
Based on the given code snippet, identify the correct statement:

A) The output is correct, and there are no errors.
B) There is a logic error, but the mileage of the first car in this case still ends up correct, while the mileage of the second car is incorrect
C) There is a logic error, but the mileage of the second car in this case still ends up correct, while the mileage of the first car is incorrect
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) There is a logic error and the mileage of both cars ends up incorrect as a result

Ans: C
Section Ref: 1.7
Title: Which is true about this snippet that calculates and prints km per liter?
Difficulty: Hard

72. Is there any error in the following code snippet, which is used for calculating the average age for a group of three students?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include

int main()
{
int age1 = 15;
int age2 = 18;
int age3 = 24;

int average = age1 + age2 + age3 / 3;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "The average is " << average;

return 0;
}

A) Yes, the code snippet has a syntax error.
B) Yes, the code snippet has a logic error.
C) Yes, the code snippet has a run-time error.
D) No error; the code snippet is completely accurate.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 1.7
Title: Is there an error in snippet that calculates average age?
Difficulty: Hard

73. What is the purpose of the following algorithm?
somenum = 0
Repeat the following steps 50 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
input variable1
if variable1 > somenum then
somenum = variable1
end of if
end of repeat
print somenum

A) To find the highest among 50 numbers
B) To print out the 50 numbers
C) To find the smallest among 50 numbers
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) To search for a particular number among 50 numbers

Ans: A
Section Ref: 1.7
Title: What is the purpose of this algorithm?
Difficulty: Medium

74. Consider a situation where you are buying videos online. The video seller charges $21.50 as the price per video and $6.75 as the handling cost for up to three videos. For every video purchased in addition to three videos, there is a handling charge of $1.50. In addition, there is a 9% tax on the cost of the videos but not on the handling charges. Assuming that num_videos represents the number of videos you are purchasing, which of the following is the correct algorithm for calculating the total cost of the videos that you are purchasing?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Total charge for the videos = 21.50 * num_videos
Tax on the videos = num_videos * .9
if (num_videos <= 3) then Handling charges = 6.75
else Handling charges = 1.50 * num_videos
Total cost of order = total charge for videos + tax + handling charges
B) Total charge for the videos = 21.50 * num_videos
Tax on the videos = num_videos * .09
if (num_videos <= 3) then Handling charges = 6.75
else Handling charges = 1.50 * num_videos
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Total cost of order = total charge for videos + tax + handling charges
C) Total charge for the videos = 21.50 * num_videos
Tax on the videos = num_videos * .09
if (num_videos < 3) then Handling charges = 6.75
else Handling charges = 6.75 + 1.50 * (num_videos – 3)
Total cost of order = total charge for videos + tax + handling charges
D) Total charge for the videos = 21.50 * num_videos
Tax on the videos = total charge for videos * .09
if (num_videos <= 3) then Handling charges = 6.75
else Handling charges = 6.75 + 1.50 * (num_videos – 3)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Total cost of order = total charge for videos + tax + handling charges

Ans: D
Section Ref: 1.7
Title: Which is the correct algorithm for calculating total cost with tax/shipping?
Difficulty: Hard

75. Consider a situation where you are planning on purchasing a new cable TV dish. You are considering two cable TV dishes. These cable TV dishes have different purchase prices. Each channel service provider charges a different rate for each month that the cable TV dish is used. To determine which cable TV dish is a better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cable TV dish. What are all of the inputs that you need for this algorithm?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The cost of each cable TV dish and the rate for each month for using each cable TV dish
B) The cost of each cable TV dish and the number of months provided with each cable TV dish
C) The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months provided with each cable TV dish
D) The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months you would use the cable TV dish

Ans: D
Section Ref: 1.7
Title: Which inputs do you need to calculate cost of purchasing/using cable dish?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

76. Consider a situation where you are assigned to develop an algorithm to calculate the total cost of a purchase order that contains several T shirts. The cost of each T shirt and the tax rate is known. The standard shipping charge for the entire order is $5.75, and the special delivery charge is $23.65. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?

A) For each T shirt on the purchase order:
Order cost = order cost + T shirt cost
Total purchase order cost = order cost + tax rate + 5.75
B) For each T shirt on the purchase order:
Order cost = order cost + T shirt cost
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
If standard shipping
Shipping cost = 5.75
Else
Shipping cost = 23.65
Total purchase order cost = order cost * tax rate + shipping cost
C) If standard shipping
Shipping cost = 5.75
Else
Shipping cost = 23.65
For each T shirt on the purchase order:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Order cost = order cost + T shirt cost + shipping cost
Total purchase order cost = order cost * tax rate
D) If special delivery
Shipping cost = 5.75
Else
Shipping cost = 23.65
For each T shirt on the purchase order:
Order cost = order cost + T shirt cost
Total purchase order cost = order cost * tax rate + shipping cost

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 1.7
Title: Which is the correct pseudocode for algorithm to calculate total cost?
Difficulty: Medium

77. Consider the given scenario for describing an algorithm using pseudocode.
WALMART Supermarket has different ways of awarding discounts to its customer IDs for each purchase they make. An 8% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer ID card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options.
I. The discount percentage
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
II. The total value of the purchase
III. The loyalty-discount amount
IV. The customer ID card number
V. The amount payable after discount

A) I, II, and III
B) I and III
C) II, IV, and V
D) II and IV

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Section Ref: 1.7
Title: What are the inputs required to solve this problem?
Difficulty: Hard

78. Evaluate the given pseudocode to calculate the payment (pmt) with the following test values:
The total number of hours worked (working_hours) = 60
The rate paid for hourly work (rate) = 15
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
input working_hours
input rate
pmt = working_hours * rate
if working_hours > 40 then
extra_hours = working_hours – 40
extra_pmt = extra_hours * rate * 2
pmt = pmt + extra_pmt
end of if
output pmt

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 900
B) 1,200
C) 1,500
D) 1,800

Ans: C
Section Ref: 1.7
Title: Evaluate this pseudocode with these test values.
Difficulty: Hard

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

1. Which statement is true?
A) Variables cannot be assigned and declared in the same statement
B) Variable names must contain at least one dollar sign
C) Variable names can be no longer than 8 characters long
D) It is incorrect to initialize a string variable with a number

Ans: D
Section Ref: 2.1.1
Title: Which statement about variable names is true?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy

2. Which statement about number literals in C++ is false?
A) One may not use a comma as a decimal separator
B) Zero is an integer
C) Integers must be positive
D) An integer with fractional part of .0 has type double.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Section Ref: 2.1.2
Title: Which statement about number literals in C++ is false?
Difficulty: Easy

3. Which option represents the best choice for a variable name to represent the average grade of students on an exam?
A) average_grade
B) $average_grade
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) avg
D) AveGd

Ans: A
Section Ref: 2.1.3
Title: Which option is the best variable name?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
4. The assignment operator
A) denotes mathematical equality
B) places a new value into a variable
C) is the same as the equals sign used in a variable declaration
D) makes it illegal to write a statement like “sum = sum + 4;”

Ans: B
Section Ref: 2.1.4
Title: What is true about the assignment operator?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

5. Which of the following statements about constants in C++ are true?
I. Although not required, constants are commonly named using uppercase letters
II. Only integer values can appear as constants
III. A variable can be defined with an initial value, but the reserved word const prevents it from being changed
IV. A named constant makes computations that use it clearer
A) I, II, III
B) II, III, IV
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) I, III, IV
D) I, II, IV

Ans: C
Section Ref: 2.1.5
Title: Which of the following statements about constants are true?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
6. What is the output of this code snippet?
int sum = 22;
sum = sum + 2;
cout << sum++; // sum = sum + 4;
cout << sum;
A) 2424
B) 2425
C) 2428
D) 2528

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 2.1.6
Title: What is the output of the code snippet?
Difficulty: Medium

7. What is the output of this code snippet?
double average;
int grade1 = 87;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int grade2 = 94;
// cout << "The average is " << (grade + grade2) / 2.0 << endl;
cout << "The average is " << average << endl;
A) Unpredictable result
B) The average is 91.5
C) The average is 91.5
The average is 91.5
D) The average is 91.5
The average is 0.0

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Section Ref: Common Error 2.2
Title: What is the output of the code snippet?
Difficulty: Medium

8. What is the output of the following code snippet?
int counter = 0;
counter++;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "The initial value of the counter is " << count << endl;
A) The initial value of the counter is 0
B) The initial value of the counter is 1
C) The code will not compile
D) The initial value of the counter is

Ans: C
Section Ref: Common Error 2.1
Title: What is the output of the code snippet (using the ++ operator and initialization of variables)?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

9. Which statements about numeric types in C++ are true?
I. There is more than one integer type
II. The data type float uses twice the storage of double
III. Numeric ranges are typical but not guaranteed to be the same between compilers
A) I, II
B) I, III
C) II, III
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) I, II, III

Ans: B
Section Ref: Special Topic 2.1
Title: Which statements about numeric types in C++ are true?
Difficulty: Easy

10. The typical ranges for integers may seem strange but are derived from
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Base 10 floating point precision
B) Field requirements for typical usage and limits
C) Overflows
D) Powers of two because of base 2 representation within the computer

Ans: D
Section Ref: Special Topic 2.2
Title: What is the reason for the ranges for integer values in C++?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

11. What is result of evaluating the following expression?
(45 / 6) % 5
A) 2
B) 7
C) 2.5
D) 3

Ans: A
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2.3
Title: What is the result of evaluating this arithmetic expression using the mod operator?
Difficulty: Easy

12. What is the difference between the result of the following two C++ statements?
I. int cents = static_cast(100 * price + 0.5);
II. int cents = (100 * price + 0.5);
A) Statement I causes truncation, but II does not
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Statement II causes truncation, but I does not
C) Statement I causes a compiler warning, but II does not
D) Statement II causes a compiler warning, but I does not

Ans: D
Section Ref: Special Topic 2.3
Title: What is the difference in execution and result between these two c++ statements?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

13. The first step in problem solving is
A) To write the expression that calculates the answer
B) To understand the problem and its inputs and outputs
C) To do examples by hand that confirm the solution will work
D) To write C++ code that can be executed and tested

Ans: B
Section Ref: 2.4
Title: What is the first step in problem solving?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy

14. At what point in the problem-solving process should one write pseudocode?
A) After writing C++ code, as a way to summarize the code’s algorithm
B) Before writing C++ code, as a guide for a general solution
C) After defining C++ variables so that the pseudocode and data types make sense
D) Before working out examples by hand in order to guide those examples

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 2.4
Title: When should pseudocode be written (in the steps for problem solving)?
Difficulty: Easy

15. The problem solving process emphasizes a “first, do-it-by-hand” approach because
A) C++ code is not able to capture the subtleties of complex problems.
B) it is faster to do computations by hand than to do them by computer.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) this guarantees that programs will be correct.
D) if programmers cannot compute a solution by hand, it is unlikely they will be able to write a program that can do it.

Ans: D
Section Ref: 2.4
Title: Why should one “do examples by hand” in problem solving?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
16. What is the output of the following code snippet?
string firstname = “William”;
string lastname;
cout << "First: " << firstname << endl;
cout << "Last: " << lastname << endl;
A) First: William
Last:
B) First: William
Last: lastname
C) Code will not compile
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Unpredictable output

Ans: A
Section Ref: 2.5.1
Title: What is the output of the code snippet (strings)
Difficulty: Medium

17. What is the correct way to invoke functions on variables in C++ that are strings?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Functions can only be invoked on string constants, not on variables.
B) For each function there is a special operator that must be used.
C) Invoke them like the mathematical functions pow() and abs().
D) Invoke them using the variable name and the dot (.) notation

Ans: D
Section Ref: 2.5.4
Title: How should functions be invoked on string variables?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

18. Suppose a phone number, stored as a ten-character string (of digits only) called phone_number, must be converted into a string that has parentheses around the area code. Which statement below will do that?
A) string new_number = “(” + phone_number.substr(3, 0) + “)”;
B) string new_number = “(” + “)” + phone_number;
C) string new_number = “(” + phone_number.substr(1, 3) + “)” + phone_number.substr(3, 7);
D) string new_number = “(” + phone_number.substr(0, 3) + “)” + phone_number.substr(3, 7);

Ans: D
Section Ref: 2.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: How do you manipulate a phone number as a string?
Difficulty: Hard

19. Which of the following options defines an integer variable?
A) Integer age;
B) integer age;
C) int age;
D) age: int;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 2.1.1
Title: Which defines an integer variable?
Difficulty: Easy

20. Which statement is true about variable names in C++?
A) They can contain the dollar sign ($)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) They can contain an underscore symbol (“_”)
C) They can contain spaces
D) They must make sense as a word

Ans: B
Section Ref: 2.1.3
Title:
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

21. Consider the following C++ variable names:
I. 1st_instance
II. basic_in_$
III. _emp_name_
IV. address_line1
V. DISCOUNT
Which of the following options is correct?
A) Only IV is a valid C++ variable name.
B) Only I and IV are valid C++ variable names.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Only I, IV, and V are valid C++ variable names.
D) Only III, IV, and V are valid C++ variable names.

Ans: D
Section Ref: 2.1.3
Title: Which is correct (about variable name)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22. Which is the appropriate time to initialize a variable?
A) When you define it
B) When you use it
C) At the end of the program
D) Before the main function

Ans: A
Title: Which is the appropriate time to initialize a variable?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.1.1

23. What is the result of the following code snippet?
#include
using namespace std;
int main()
{
double bottles;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
double bottle_volume = bottles * 2;
cout << bottle_volume << endl;
return 0;
}
A) 0
B) 1
C) 2
D) Unpredictable result

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the result of snippet (with assignment)?
Difficulty: Medium
Section Ref: Common Error 2.2

24. Which one of the following is a correct method of defining and initializing an integer variable with name value?
A) int value = 30;
B) Int value = 30;
C) int value = .30;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Int value = .30;

Ans: A
Title: Which correctly defines and initializes an integer variable value?
Difficulty: Easy
Section Ref: 2.1

25. What is wrong with the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
int size = 42;
cost = 9.99;
cout << "size = " << size << " cost = " << cost << endl;
return 0;
}
A) The code snippet uses a variable that has not yet been initialized.
B) The code snippet uses a variable that has not been defined.
C) The code snippet attempts to assign a decimal value to an integer variable.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The code snippet attempts to assign an integer value to a decimal variable.

Ans: B
Section Ref: Common Error 2.1
Title: What is wrong with snippet (with undefined variable)?
Difficulty: Medium

26. Which one of the following reserved words is used in C++ to represent a value without a fractional part?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) integer
B) int
C) Int
D) Integer

Ans: B
Title: Which reserved word represents a value without a fractional part?
Difficulty: Easy
Section Ref: 2.1.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

27. In an airline reservation system, the number of available seats in an airplane is required. Which data type should be used to store this value?
A) double
B) float
C) int
D) long

Ans: C
Title: Which data type should store the number of available seats in an airplane?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 2.1

28. In an airline reservation system, the cost of an airline ticket is required. Which data type should be used to store this value?
A) int
B) unsigned int
C) double
D) short
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Title: Which data type should store the cost of an airline ticket?
Difficulty: Easy
Section Ref: 2.1

29. What is wrong with the following code snippet?
int price;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
price = 9.42;
A) The price variable is never initialized.
B) The data type for the price variable is not specified.
C) The price variable is never assigned a value.
D) The price variable is assigned a decimal value, but it can store only a whole number value.

Ans: D
Title: What is wrong with snippet (with value assigned to variable)?
Difficulty: Medium
Section Ref: 2.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

30. Which one of the following is an assignment statement?
A) int a = 20;
B) a = 20;
C) assign a = 20;
D) assign 20 to a;

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which is an assignment statement?
Difficulty: Easy
Section Ref: 2.1.4

31. Which one of the following types of statements is an instruction to replace the existing value of a variable with another value?
A) Update
B) Declaration
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Assignment
D) Initialization

Ans: C
Section Ref: 2.1.4
Title: Which statement replaces the existing value of a variable with another value?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
32. What is the meaning of x = 0; in C++?
A) It checks whether x equals 0.
B) It sets the variable x to zero.
C) It defines a variable named x and initializes it with 0.
D) It is a syntax error since x is not always 0.

Ans: B
Title: What is the meaning of x = 0; in C++?
Difficulty: Easy
Section Ref: 2.1.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

33. What are the values of num1 and num2 after this snippet executes?
double num1 = 4.20;
double num2 = num1 * 10 + 5.0;
A) num1 = 4.20 and num2 = 63.0
B) num1 = 4.20 and num2 = 47.0
C) num1 = 42.0 and num2 = 42.0
D) num1 = 42.0 and num2 = 47.0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Section Ref: 2.2
Title: What are num1 and num2 after snippet (with assignment)?
Difficulty: Medium

34. What is the result of the following expression?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
double d = 2.5 + 4 * -1.5 – (2.5 + 4) * -1.5;
A) 24.375
B) 6.25
C) 12.375
D) 6

Ans: B
Section Ref: 2.2.1
Title: What is the result of (arithmetic) expression?
Difficulty: Hard
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

35. What is the output of the following code snippet?
#include
using namespace std;
int main()
{
int value = 3;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
value++;
cout << value << endl;
return 0;
}
A) 2
B) 3
C) 4
D) No output due to syntax error

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2
Title: What is output of snippet (with increment)?
Difficulty: Easy

36. What is the output of the following code snippet?
#include
using namespace std;
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
int value = 25;
value = value * 2;
value–;
cout << value << endl;
return 0;
}
A) 25
B) 50
C) 49
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) No output due to syntax error

Ans: C
Section Ref: 2.2
Title: What is output of snippet (with decrement)?
Difficulty: Easy

37. Which of the following statements places input into the variable “value”?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) value >> cin;
B) cin >> value;
C) value << cin;
D) cin << value;

Ans: B
Section Ref: 2.3
Title: Which statement places input into the variable “value”?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

38. Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code snippet, what is the output?
int main()
{
cout << "Enter the price: ";
double price;
cin >> price;

cout << "Enter the discount rate: ";
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
double discount;
cin >> discount;

cout << "The new price is "
<< price – price * (discount / 100.0) << endl;
return 0;
}
A) The new price is 25
B) The new price is 15
C) The new price is 22.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The new price is 20.0

Ans: C
Section Ref: 2.2
Title: What is output of snippet (that calculates value based on user input)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
39. Consider the following code snippet:
cout << "Please enter a number: ";
int x;
cin >> x;
cout << "Please enter another number: ";
int y;
cin >> y;
cout << "The sum is " << x + y << endl;
Suppose the student provides the answer 17 29 [Enter] as input to the first prompt. What will the program do?
A) Print “The sum is 17”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Print “The sum is 46”
C) Produce an error because the input for the first prompt is not a single integer
D) Produce an error because no value was provided after the second prompt

Ans: B
Section Ref: 2.3
Title: What will snippet do (with given user input of two values)?
Difficulty: Hard

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

40. Which of the following statements is correct about constants?
A) Constants are written using uppercase letters because the compiler ignores the constants declared in lowercase letters.
B) The data stored inside a const variable can be changed using an assignment statement.
C) You can make a variable constant by using the constant reserved word while declaring the variable.
D) Variables defined using const make a code snippet more readable and easier to maintain.

Ans: D
Section Ref: 2.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement is correct about constants?
Difficulty: Medium

41. Which one of the following operators computes the remainder of an integer division?
A) /
B) %
C)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) !

Ans: B
Section Ref: 2.2
Title: Which operator computes the remainder of an integer division?
Difficulty: Easy

42. What is the value of pow(2, 3)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 5
B) 6
C) 8
D) 9

Ans: C
Section Ref: 2.2
Title: What is the value of pow(2, 3)?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

43. What is the output of the following code snippet?
int main()
{
double a;
a = sqrt(9.0) + sqrt(16.0);
cout << a << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 25.0
B) 34
C) 7.0
D) Compilation error

Ans: C
Section Ref: 2.2
Title: What is output of snippet (with sqrt function)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

44. Which is the C++ equivalent of the following mathematical expression?
c = √(a2 + b2)
A) c = sqrt(a * 2 + b * 2);
B) c = sqrt(a * 2) + sqrt(b * 2);
C) c = sqrt(pow(a, 2) + pow(b, 2));
D) c = sqrt(pow(a, 2)) + sqrt(pow(b, 2));

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2
Title: Which is the C++ equivalent of this mathematical expression?
Difficulty: Medium

45. Which one of the following is a correct representation of the given mathematical expression in C++?
a + b
2
A) a + b % 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) a + b / 2
C) a + (b / 2)
D) (a + b) / 2

Ans: D
Section Ref: 2.2
Title: Which is the C++ equivalent of this mathematical expression?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

46. Given the definition const double PI = 3.14159; which of the following is the C++ equivalent of the mathematical expression c = π · radius2
A) c = PI * (radius * 2);
B) c = PI * pow(2, radius);
C) c = PI * pow(radius, 2);
D) c = pow(PI * radius, 2);

Ans: C
Title: Which is the C++ equivalent of this mathematical expression?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2

47. Which of the following is the mathematical equivalent of the following C++ expression?
h = (4.0 * a * b – pow(b, 2)) / c;
A) h = 4ab – 2b / c
B) h = (4ab – 2b) / c
C) h = 4ab – b2 / c
D) h = (4ab – b2) / c
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: Which is the mathematical equivalent of C++ expression?
Difficulty: Medium
Section Ref: 2.2

48. Which of the following statements displays
price = 20.00?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) cout << "price = " << setw(3) << fixed << setprecision(2) << 20;
B) cout << "price = " << setw(8) << fixed << setprecision(2) << 20;
C) cout << "price = " << setw(8) << fixed << 20.00;
D) cout << "price = " << fixed << setw(2) << 20;

Ans: C
Title: Which statement displays (this formatted output)?
Difficulty: Easy
Section Ref: 2.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

49. What is the output of the following code snippet?
#include
#include
using namespace std;
int main()
{
cout << fixed << setprecision(3) << 20 << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) 20
B) 20.0
C) 20.00
D) 20.000

Ans: D
Title: What is output of snippet (using setprecision flag)?
Difficulty: Easy
Section Ref: 2.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

50. Consider the following C++ statement:
string name = “Harry”;
Which of the following is true?
A) name is a string literal.
B) name is a string variable.
C) “Harry” is a string variable.
D) The statement contains a syntax error.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: Which is true (about definition of string variable)?
Difficulty: Hard
Section Ref: 2.5

51. Which one of the following is defined as a sequence of characters?
A) String
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Constant
C) Integer
D) Variable

Ans: A
Title: Which is defined as a sequence of characters?
Difficulty: Simple
Section Ref: 2.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

52. Which of the following statements are valid about strings?
I. An empty string literal is represented as “”.
II. A string stored in a string variable can be changed.
III. String variables are initialized automatically.
IV. A string variable can contain digits and special characters.
A) Only II and III are valid.
B) Only III and IV are valid.
C) Only I and III are valid.
D) All four statements are valid.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: Which statement is valid about strings?
Difficulty: Medium
Section Ref: 2.5

53. What is the result of the following statement?
string s = “New” + ” ” + “Jersey”;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The string s has the following value: “New Jersey”
B) The statement results in an error because the + operator can be used only with numbers.
C) The statement results in an error because the + operation cannot be performed on string literals.
D) The string s has the following value: “NewJersey”

Ans: C
Title: What is result of statement (that uses + with strings)?
Difficulty: Hard
Section Ref: 2.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

54. Which operator is used to concatenate two or more strings?
A) +
B) %
C) &
D) ^

Ans: A
Title: Which operator is used to concatenate two or more strings?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 2.5

55. What output is produced by these statements?
string name = “Joan Hunt”;
cout << name.length();
A) 4
B) 8
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 9
D) 11

Ans: C
Title: What output is produced by (sending string length to cout)?
Difficulty: Medium
Section Ref: 2.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
56. In C++, which special character is used to invoke a member function?
A) A semicolon
B) A colon
C) A dot
D) A comma

Ans: C
Title: Which special character is used to invoke a member function?
Difficulty: Easy
Section Ref: 2.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

57. How do you compute the length of the string str?
A) length(str)
B) length.str
C) str.length
D) str.length()

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: How do you compute the length of the string str?
Difficulty: Medium
Section Ref: 2.5

58. What is the output of the following code snippet?
int main()
{
string str1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
str1 = “I LOVE MY COUNTRY”;
string str2 = str1.substr(4, 5);
cout << str2 << endl;
return 0;
}
A) I LOV
B) I LOVE
C) V
D) VE MY

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is output of snippet (with substr)?
Difficulty: Medium
Section Ref: 2.4

59. What is the output of the following code snippet?
#include
using namespace std;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
int s;
double f = 365.25;

s = f / 10;

cout << s << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 36
B) 36.525
C) 37
D) No output because the code snippet generates compilation errors

Ans: A
Section Ref: 2.1
Title: What is output of snippet (with division)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

60. Which of the following guidelines will make C++ code more explanatory for others?
A) Use more English statements in a code.
B) Add comments to code.
C) Avoid usage of complex calculations in code.
D) Always enclose the statements in curly braces in code.

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.1
Title: Which of the following guidelines will make code more explanatory for others?
Difficulty: Easy

61. What will be the output of the following code snippet?
int a = 10;
int b = 20;
int c = 2;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

int x = b / a /*c*/;
A) 1
B) 2
C) 4
D) No output, due to compilation error

Ans: B
Section Ref: 2.1
Title: What is output of snippet (with arithmetic expression)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

62. Which one of the following variables is assigned with valid literals?
A) int salary = 0; salary = 5000.50;
B) unsigned short salary1 = 0; salary1 = 1E6;
C) double salary2 = 0; salary2 = 2.96E-2;
D) unsigned long salary3 = 0; salary3 = 1E-6;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Section Ref: 2.2
Title: Which variable is assigned with valid literals?
Difficulty: Medium

63. What will be the value inside the variables a and b after the given set of assignments?
int a = 20;
int b = 10;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

a = (a + b) / 2;
b = a++;

A) a = 15, b = 16
B) a = 16, b = 16
C) a = 16, b = 15
D) a = 15, b = 15

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2
Title: What is the value of a and b after these assignments?
Difficulty: Medium

64. What is the value inside the value variable at the end of the given code snippet?
#include
using namespace std;
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
int value = 3;
value = value – 2 * value;
value++;
return 0;
}
A) –2
B) 0
C) 2
D) 4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Section Ref: 2.2
Title: What is value after this snippet (with assignment and increment)?
Difficulty: Easy

65. Assuming that the user inputs “Joel” at the prompt, what is the output of the following code snippet?
#include
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
using namespace std;
int main()
{
cout << "Enter your name ";
string name;
cin >> name;

name += “, Good morning”;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << name << endl;
return 0;
}
A) The code snippet does not compile because the += operator cannot be used in this context.
B) Joel, Good morning
C) , Good morning
D) Joel

Ans: B
Section Ref: 2.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of snippet (using += with string variable)?
Difficulty: Medium

66. Which one of the following refers to a number constant that appears in code without explanation?
A) Constant
B) Variable
C) Magic Number
D) String literal
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Section Ref: 2.1
Title: Which refers to a number constant that appears without explanation?
Difficulty: Easy

67. What happens to the fractional part when performing a division on two integer variables?
A) The result is rounded off to the nearest integer value.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The fractional part is discarded.
C) Two integers cannot be used in division; at least one of the operands should be a floating point number.
D) Instead of using an integer division, you should use the modulus operator if you want to perform floating-point division.

Ans: B
Title: What happens to the fractional part (in integer division)?
Difficulty: Medium
Section Ref: 2.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

68. Consider the following division statements:
I. 22 / 7
II. 22.0 / 7
III. 22 / 7.0
IV. 22.0 / 7.0
Which of the following options is correct?
A) All the four statements will return an integer value.
B) Only I will return an integer value.
C) Only I, II, and III will return an integer value.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Only II and III will return an integer value.

Ans: B
Section Ref: 2.2
Title: Which is correct (about four division statements)?
Difficulty: Hard

69. Which of the following choices is a valid statement about this code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
using namespace std;
int main()
{
double d = 45.326;
double r = d % 9.0;
cout << r;
return 0;
}
A) The value inside the variable r will be 0.326
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The value inside the variable r will be 5.036
C) Variable r has to be defined as an integer because the % operator always returns an integer
D) The assignment statement for variable r is wrong, because the % operator expects integer values as operands

Ans: D
Section Ref: 2.3
Title: Which is valid for this snippet (using modulo)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

70. What is the output of the following code snippet?
#include
#include
using namespace std;
int main()
{
int var1 = 10;
int var2 = 2;
int var3 = 20;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
var3 = var3 / (var1 % var2);
cout << var3 << endl;
return 0;
}
A) 0
B) 4
C) 20
D) There will be no output due to a run-time error.

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2
Title: What is output of snippet (using modulo)?
Difficulty: Hard

71. Which one of the following statements gives the absolute value of the floating-point number 
x = -25.50 in C++?
A) abs(x);
B) pos(x);
C) x.abs();
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) x.pos();

Ans: A
Section Ref: 2.2
Title: Which statement gives the absolute value of this floating-point number?
Difficulty: Easy

72. Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
#include
using namespace std;
int main()
{
cout << "Enter a number: ";
string n1;
cin >> n1;

cout << "Enter another number: ";
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
string n2;
cin >> n2;

string result = n1 + n2;

cout << result << endl;
return 0;
}
A) 46
B) No output due to a run-time error
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 107
D) 4562

Ans: D
Title: What is output of snippet (that “adds” two numbers stored as strings)?
Difficulty: Medium
Section Ref: 2.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
73. Which of the following member functions is used to find the number of characters in a string?
a) len
b) length
c) char
d) substr

Ans: B
Section Ref: 2.4
Title: Which member function finds the number of characters in a string?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

74. Which of the functions given below require the dot notation to get invoked?
I. len
II. length
III. substr
IV. pow
V. sqrt
A) All the five functions are called with the dot notation
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Only I, II and III
C) only IV and V
D) Only II and III

Ans: D
Section Ref: 2.5
Title: Which of these functions requires the dot notation?
Difficulty: hard

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

75. Which one of the following statements can be used to extract the last five characters from any string variable?
A) str.substr(str.length() – 5, 5)
B) str.substr(5, 5)
C) str.substr(str.length() – 4, 5)
D) str.substr(0, 5)

Ans: A
Section Ref: 2.5
Title: Which statement extracts the last five characters from any string variable?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard

76. What is the output of the following code snippet if the user provides NEW YORK as the input?
#include
#include
using namespace std;
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
string name;
cout << "ENTER THE STRING: ";
cin >> name;
int s1 = name.length();
cout << s1 << endl;
return 0;
}
A) 8
B) 7
C) 3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 4

Ans: C
Section Ref: 2.5
Title: What is output of snippet (with string.length) with this input?
Difficulty: Medium

77. Which of the following options defines a double variable?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Double age;
B) dbl age;
C) double age;
D) age: double;

Ans: C
Section Ref: 2.1
Title: Which declares a double variable?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

78. What is the result of the following code snippet?
#include
using namespace std;
int main()
{
double circle_radius;
double circle_volume = 22 / 7 * circle_radius * circle_radius;
cout << circle_volume << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}
A) 0
B) 3.14
C) 6.28
D) Unpredictable result

Ans: D
Section Ref: 2.1
Title: What is result of snippet (with assignment)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

79. What is wrong with the following code snippet?
int main()
{
int width = 10;
height = 20.00;
cout << "width = " << width << " height = " << height << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}
A) The code snippet uses an uninitialized variable.
B) The code snippet uses an undefined variable.
C) The code snippet attempts to assign a decimal value to an integer variable.
D) The code snippet attempts to assign an integer value to a decimal variable.

Ans: B
Section Ref: 2.1
Title: What is wrong with snippet (with variable error)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

80. What is wrong with the following code snippet?
int average;
average = 78.5980;
A) The average variable is never initialized.
B) The data type for the average variable is not specified.
C) The average variable is never assigned a value.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The average variable is assigned a decimal value, but it can store only a whole number value.

Ans: D
Title: What is wrong with snippet (with value assigned to variable)?
Difficulty: Medium
Section Ref: 2.1

81. What is the meaning of num = 10; in C++?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) It checks whether num equals 10.
B) It sets the variable num to ten.
C) It declares a variable named num and initializes it with 10.
D) It gives a syntax error since num cannot be assigned a value using = operator.

Ans: B
Section Ref: 2.1
Title: What is the meaning of num = 10; in C++?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

82. What is the result of the following snippet?
int son_age = 5;
int father_age = son_age * 3 + 5;
A) son_age = 5 and father_age = 15
B) son_age = 5 and father_age = 20
C) son_age = 15 and father_age = 45
D) son_age = 15 and father_age = 50

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Section Ref: 2.2
Title: What are son_age and father_age after snippet (with assignment)?
Difficulty: Medium

83. Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus rate in the following code snippet, what is the output?
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "Enter the pay: ";
double pay;
cin >> pay;

cout << "Enter the bonus rate: ";
double bonus;
cin >> bonus;

cout << "The new pay is "
<< pay + pay * (bonus / 100.0) << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}
A) The new pay is 25000
B) The new pay is 25100
C) The new pay is 27500
D) The new pay is 30000

Ans: C
Section Ref: 2.3
Title: What is output of snippet (that calculates value based on user input)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium

84. Consider the following code snippet:
cout << "Please enter a number: ";
int num1;
cin >> num1;
cout << "Please enter another number: ";
int num2;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cin >> num2;
cout << "The product is " << num1 * num2 << endl;
Suppose the student provides the answer 2 5 [Enter] as input to the first prompt. What will the program do?

A) Print “The product is 25”
B) Print “The product is 10”
C) Produce an error because the input for the first prompt is not a single integer
D) Produce an error because no value was provided after the second prompt

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.3
Title: What will snippet do (with given user input of two values)?
Difficulty: Hard

85. What is the value of abs(-2)?
A) -2
B) 0
C) 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 4

Ans: C
Section Ref: 2.2
Title: What is the value of abs(-2)?
Difficulty: Easy

86. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
double x;
x = pow(3.0, 2.0) + pow(4.0, 2.0);
cout << x << endl;
return 0;
}
A) 25.0
B) 34
C) 7.0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Compilation error

Ans: A
Section Ref: 2.2
Title: What is output of snippet (with pow function)?
Difficulty: Medium

87. Which is the C++ equivalent of the following mathematical expression?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
c = (√a + √b)2
A) c = sqrt(a * 2 + b * 2);
B) c = sqrt(a * 2) + sqrt(b * 2);
C) c = sqrt(pow(a, 2) + pow(b, 2));
D) c = pow((sqrt(a) + sqrt(b)), 2);

Ans: D
Section Ref: 2.2
Title: Which is the C++ equivalent of this mathematical expression?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

88. Given the definition const double PI=3.14159; which of the following is the C++ equivalent of the mathematical expression p = 2 · π· (radius)3
A) p = 2 * PI * (radius * 3);
B) p = PI * pow(3, radius);
C) p = 2 * PI * pow(radius, 3);
D) p = 2 * pow(PI * radius, 3);

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.2
Title: Which is the C++ equivalent of this mathematical expression?
Difficulty: Medium

89. Which of the following statements displays
basic = 500.00?
A) cout << "basic = " << setw(4) << fixed << setprecision(2) << 500;
B) cout << "basic = " << setw(10) << fixed << setprecision(2) << 500;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) cout << "basic = " << setw(10) << fixed << 500.00;
D) cout << "basic = " << fixed << setw(4) << 500;

Ans: C
Section Ref: 2.3
Title: Which statement displays (this formatted output)?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
90. What is the output of the following code snippet?
#include
#include
using namespace std;
int main()
{
cout << fixed << setprecision(5) << 500.0 << endl;
return 0;
}
A) 500
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 500.0
C) 500.000
D) 500.00000

Ans: D
Section Ref: 2.3
Title: What is output of snippet (using setprecision flag)?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

91. What output is produced by these statements?
string city = “Rio de Janeiro”;
cout << city.length();
A) 12
B) 13
C) 14
D) 15

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 2.5
Title: What output is produced by (sending string length to cout)?
Difficulty: Medium

92. How do you extract first 5 characters from the string str?
A) substr(str, 5)
B) substr.str(0, 5)
C) str.substr(5)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) str.substr(0, 5)

Ans: D
Section Ref: 2.5
Title: How do you extract first 5 characters from the string str?
Difficulty: Medium

93. The swap() member function of the string class exchanges two strings. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
string str1 = “I LOVE MY DOG”;
string str2 = “I HATE MY CAT”;
str1.swap(str2);
cout << str1 << endl;
cout << str2 << endl;
return 0;
}
A) I LOVE MY DOG
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
I HATE MY CAT
B) I LOVE MY DOG
I LOVE MY DOG
C) I LOVE MY CAT
I HATE MY DOG
D) I HATE MY CAT
I LOVE MY DOG

Ans: D
Section Ref: 2.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of snippet (with swap)?
Difficulty: Medium

94. What is the output of the following code snippet?
#include
using namespace std;
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
short x;
double d = 366.25;
x = d / 100;
cout << x << endl;
return 0;
}
A) 3
B) 3.6625
C) 3.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) No output because the code snippet generates compilation errors

Ans: A
Section Ref: 2.2
Title: What is output of snippet (with division)?
Difficulty: Medium

95. What will be the value inside the variables x and y after the given set of assignments?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int x = 20;
int y = 10;

x = (x – y) * 2;
y = x–;
A) x = 19, y = 19
B) x = 20, y = 19
C) x = 19, y = 20
D) x = 20, y = 20

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Section Ref: 2.2
Title: What is the value of x and y after these assignments?
Difficulty: Medium

96. What is the value inside the var variable at the end of the given code snippet?
#include
using namespace std;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
int var = 30;
var = var + 2 / var;
var++;
return 0;
}
A) 0
B) 1
C) 30
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 31

Ans: D
Section Ref: 2.2
Title: What is var after this snippet (with assignment and increment)?
Difficulty: Easy

97. Which of the following statements will give the result as an integer value?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 22 / 7
B) 22.0 / 7
C) 22 / 7.0
D) 22.0 / 7.0

Ans: A
Section Ref: 2.3
Title: Which (division) statement will give the result as an integer value?
Difficulty: Hard

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

98. What is the output of the following code snippet?
#include
#include
using namespace std;
int main()
{
int num1 = 10;
int num2 = 5;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int num3 = 200;
num3 = num3 % (num1 * num2);
cout << num3 << endl;
return 0;
}
A) 0
B) 4
C) 10
D) There will be no output due to a run-time error.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Section Ref: 2.2
Title: What is output of snippet (using modulo)?
Difficulty: Hard

99. Which one of the following statements gives the square root value of the floating-point number x = 25 in C++?
A) sqrt(x);
B) sqr(x);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) x.sqr();
D) x.sqrt();

Ans: A
Section Ref: 2.2
Title: Which statement gives the square root value of this floating-point number?
Difficulty: Easy

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

100. Assuming that the user enters 23 and 45 as inputs for num1 and num2, respectively, what is the output of the following code snippet?
#include
#include
using namespace std;
int main()
{
cout << "Enter a number: ";
string num1;
cin >> num1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

cout << "Enter another number: ";
string num2;
cin >> num2;

string final = num1 + num2;

cout << final << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 23
B) No output due to a run-time error
C) 68
D) 2345

Ans: D
Section Ref: 2.5
Title: What is output of snippet (that “adds” two numbers stored as strings)?
Difficulty: Medium

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

101. Which one of the following statements can be used to extract the last 10 characters from the string variable str?
A) str.substr(str.length()-10, 10)
B) str.substr(10, 10)
C) str.substr(str.length()-9, 10)
D) str.substr(0, 10)

Ans: A
Section Ref: 2.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement extracts the last 10 characters from the string variable str?
Difficulty: Hard

1. What are the two parts of an if statement?
A) A condition and a body
B) A check and an increment
C) An increment and a body
D) An increment and a decrement

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What are the two parts of an if statement?Difficulty: EasySection Ref: 3.1

2. Which of the following statements is true about the if statement?
A) The if statement can have only one condition that evaluates to an integer value.
B) The if block is optional.
C) The else block is optional.
D) The if and else blocks should always be included within curly braces.
Ans: CTitle: Which statement is true about the if-else statement?Difficulty: EasySection Ref: 3.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
3. Which of the following statements is correct about an if-else statement?
A) You must use braces if the body of an if statement contains only a single statement.
B) You can omit an else statement if there is no task defined in the else branch.
C) You cannot use braces if the body of an if statement contains only a single statement.
D) The number of opening braces can be different from the number of closing braces.
Ans: BTitle: Which statement is true about the if-else statement?Difficulty: MediumSection Ref: 3.1

4. Which of the following is the correct syntax for an if-else statement?
A) if (x < 10) { size = "Small"; }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
else (x < 20) { size = "Medium"; }
B) if (x < 10); { size = "Small"; }
else (x < 20) { size = "Medium"; }
C) if (x < 10) { size = "Small"; }
else { size = “Medium”; }
D) if { size = “Small”; }
else (x < 20) { size = "Medium"; }
Ans: CTitle: Which is the correct syntax for an if-else statement?Difficulty: MediumSection Ref: 3.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

5. Assuming that the user provides 101 as input, what is the output of the following code snippet?
int a;
int b;a = 0;cout <> b;if (b > 100) { a = b; }else { a = 0; }cout << "a: " << a << endl;
A) a: 0
B) a: 100
C) a: 101
D) There is no output due to compilation errors.
Ans: CTitle: What is output of (if/else) snippet with this input?Difficulty: HardSection Ref: 3.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

6. Assuming that the user provides 99 as input, what is the output of the following code snippet?
int a;
int b;a = 0;cout <> b;if (b > 100);{ a = b;}cout << "a: " << a << endl;
A) a: 0
B) a: 99
C) a: 100
D) There is no output due to compilation errors.
Ans: A
Title: What is output of (if with > test) snippet with this input?Difficulty: HardSection Ref: 3.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

7. The following code snippet contains an error. What is the error?
int cost = 0;
cin >> cost;
if (cost > 100);
{
cost = cost – 10;
}
cout << "Discount cost: " << cost << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Syntax error (won’t compile)
B) Logical error: use of an uninitialized variable
C) Logical error: if statement has do-nothing statement after if condition
D) Logical error: assignment statement does not show equality

Ans: C
Title: What is the error in this if statement?
Difficulty: MediumSection Ref: Common error 3.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

8. What can be done to improve the following code fragment?
int counter = 0;
while (counter < 10000)
{
if ((counter % 10) == 0)
{
cout << "Counter is divisible by ten: " << counter << endl;
counter++;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
else
{
cout << "Counter is not divisible by ten: " << counter
<< endl;
counter++;
}
}
A) move the duplicated code outside of the if statement
B) use tabs to make alignment neater
C) move the brackets to save several lines of code
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) add semicolons after the if condition and the else reserved word

Ans: A
Title: What can be done to improve the code fragment containing an if statement?
Difficulty: MediumSection Ref: Section 3.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
9. What kind of operator is the <= operator?
A) Ternary
B) Arithmetic
C) Inequality
D) Relational
Ans: D
Title: What kind of operator is the <= operator?Difficulty: EasySection Ref: 3.2
10. Which of the following operators is used as a relational operator?
A) =<
B) <=
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) =
D) !
Ans: BTitle: Which of the following is a relational operator?Difficulty: EasySection Ref: 3.2

11. The operator !> stands for
A) not less than
B) not greater than
C) not equal to
D) this is not an operator in C++
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: Which relational operator is this?
Difficulty: Easy
Section Ref: 3.2

12. Assuming that a user enters 15 as input, what is the output of the following code snippet?
int main(){ int number; cout <> number; if (number > 20) { cout << "The number is LARGE!" << endl; } else { cout << "The number is SMALL!" << endl; } return 0;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) There is no output due to compilation errors.
B) The number is LARGE!
C) The number is SMALL!
D) The number is LARGE!
The number is SMALL!
Ans: CTitle: What is output of (if/else with < test) with this input?Difficulty: MediumSection Ref: 3.2
13. What is the output of the following code snippet if the input is 25?
#include using namespace std;int main(){ int i; cout <> i; if (i > 25) { i++; } else { i–; } cout << i << endl; return 0;}
A) 24
B) 25
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 26
D) 27
Ans: ATitle: What is output of (if/else with increment/decrement) with this input?Difficulty: MediumSection Ref: 3.2
14. A store provides 10% discount on all items with a price of at least $100. No discount is otherwise applicable. Which of the following statements DOES NOT correctly compute the discount?
A) double discount = 0; if (price >= 100) { discount = 0.10 * price; }
B) double discount = 0.10 * price; if (price <= 100) { discount = 0; }
C) double discount; if (price < 100) { discount = 0; } else { discount = 0.10 * price; }
D) double discount = 10; if (price >= 100) discount = 0.1 * price; else discount = 0;
Ans: BTitle: Which statement DOES NOT correctly compute the discount?Difficulty: EasySection Ref: 3.1
15. Which of the following statements is true about an if statement?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) It guarantees that several statements are always executed in a specified order.
B) It repeats a set of statements as long as the condition is true.
C) It allows the program to carry out different actions depending on the value of a condition.
D) None of the listed options is true.
Ans: CTitle: TB 3.12 Which statement is true about an if statement?Difficulty: EasySection Ref: 3.1
16. What is the output of the following code snippet?
int main()
{ double income = 45000; double cutoff = 55000; double min_income = 30000; if (min_income > income) { cout << "Minimum income requirement is not met." << endl; } if (cutoff < income) { cout << "Maximum income limit is exceeded." << endl; } else { cout << "Income requirement is met." << endl; } return 0;}
A) Minimum income requirement is not met.
B) Maximum income limit is exceeded.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Income requirement is met.
D) There is no output.
Ans: CTitle: What is output of (if/if/else) snippet?Difficulty: MediumSection Ref: 3.1
17. In C++, which of the following orderings is used to compare strings?
A) Lexicographic
B) Semantic
C) Cyclic
D) Syntactic
Ans: ATitle: Which ordering is used to compare strings?Difficulty: EasySection Ref: 3.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

18. Suppose one needs an if statement to check whether an integer variable pitch is equal to 440 (which is the frequency of the note “A” to which strings and orchestras tune). Which condition is correct?
A) if (pitch – 440 = 0)
B) if ( (pitch ! 440) )
C) if (pitch = 440)
D) if (pitch == 440)

Ans: D
Title: Which condition for an if statement is correct?
Difficulty: M
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: Common Error 3.2

19. Which statement about an if statement is true?
A) The condition in an if statement using relational operators will evaluate to a Boolean result
B) The condition in an if statement should make exact comparisons to floating-point numbers
C) The condition in an if statement should always evaluate to true
D) The condition in an if statement should never include integer variables

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What is the expected type of the conditional in an if statement?
Difficulty:
Section Ref: 3.2

20. What is the problem with the following if statement?
double count = 15.0;
if (count / 3.0)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << "The value of count is " << count << endl;
}
A) There should be an “else” condition
B) The condition does not evaluate to a Boolean value
C) The variable count is not initialized
D) It is never possible to use the “/” operator in an if statement

Ans: B
Title: What is wrong with the given if statement?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 3.2

21. Consider the following code snippet. What is the potential problem with the if statement?
double average;
average = (g1 + g2 + g3 + g4) / 4.0;
if (average == 90.0)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "You earned an A in the class!" << endl;
}
A) Using == to test the double variable average for equality is error-prone.
B) The conditional will not evaluate to a Boolean value.
C) The assignment operator should not be used within an if-statement conditional.
D) Constants should never be used in if-statement conditionals.

Ans: A
Title: What is wrong with the following if statement?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: Common Error 3.3

22. Which code snippet will output “Yes!” when two strings s1 and s2 are equal?
A) if (s1 = s2) { cout << "Yes!" << endl; }
B) if (s1 == s2) { cout << "Yes!" << endl; }
C) if (s1 < s2) { cout << "Yes!" << endl; }
D) if (s1 != s2) { cout << "Yes!" << endl; }

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which code snippet correctly implements the required conditional?
Difficulty: Easy
Section Ref: Special Topic 3.2

23. Which condition, when supplied in the if statement below in place of (. . .), will correctly protect against division by zero?
if (. . .)
{
result = grade / num;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "Just avoided division by zero!" << endl;
}
A) (grade == 0)
B) ((grade / num) == 0)
C) (num == 0)
D) (num != 0)

Ans: D
Title: Which condition avoids division by zero?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 3.2

24. What is the output of the following code snippet?
int main(){ int num = 100; if (num != 100) { cout << "100" << endl; } else { cout << "Not 100" << endl; } return 0;}
A) There is no output due to compilation errors.
B) 100
C) Not 100
D) 100
Not 100
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: CTitle: What is output of (if/else with != test)?Difficulty: HardSection Ref: 3.2

25. What is the output of the following code snippet?
#include #include using namespace std;int main(){ string str1 = “her”; string str2 = “cart”; if (str1 < str2) { cout << str2; } else { cout << str1; } return 0;}
A) her
B) hercart
C) cart
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) There is no output due to compilation errors.
Ans: ATitle: What is output of (if/else with string ordering test)?Difficulty: MediumSection Ref: 3.2

26. What is the conditional required to check to see if the length of a string s1 is odd?
A) if ((s1.length() % 2) == 0)
B) if ((s1.length() % 2) != 0)
C) if ((s1.length() / 2))
D) if ((s1.length() * 2))

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: What condition evaluates to true if the length of a string s1 is odd?
Difficulty: Medium
Section Ref: 3.2

27. The two strings “Aardvark” and “Aardvandermeer” are exactly the same up to the first six letters. What is their correct lexicographical ordering?
A) They cannot be compared lexicographically unless they are the same length
B) “Aardvandermeer” is first, then “Aardvark”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) “Aardvark is first, then “Aardvandermeer”
D) The shorter word is always first

Ans: B
Title: Which is the correct application of lexicographical ordering?
Difficulty: Medium
Section Ref: 3.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
28. Write an if-statement condition that is true if the length of string s1 is greater than 42.
A) if (s1.length() > 42)
B) if (s1.length() != 42)
C) if (42 > s1.length())
D) if (42 != s1.length())

Ans: A
Title: Which if statement is true when the length of string s1 is greater than 42?
Difficulty:
Section Ref: 3.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

29. Which of the following options is a legally correct expression for inverting a condition?
A) if (!(a == 10))
B) if (!a == 10)
C) if (a !== 10)
D) if (a ! 10)
Ans: ATitle: TB 3.17 Which is a correct expression for inverting a condition?Difficulty: Easy
Section Ref: 3.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

30. Suppose you want to write an if statement with multiple alternatives to print out the single tax bracket that someone is in, based on their income. Assume the integer variable income holds the annual income. What is wrong with the following if statement?
if (income < 10000)
{
cout << "Lowest tax bracket" << endl;
}
if (income < 20000)
{
cout << "Low-Middle tax bracket" << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
if (income < 30000)
{
cout << "Middle tax bracket" << endl;
}
cout << "High tax bracket" << endl;

A) The if conditions are in the wrong order; the check for the highest bracket should be first
B) The conditions should use a sequence of if else/if clauses, not just independent if statements
C) The if conditions should be a switch statement instead
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Nothing is wrong – the if statement will correctly print out the tax brackets

Ans: B
Title: Is the given if statement with multiple alternatives written correctly?
Difficulty: Medium
Section Ref: 3.3

31. The switch statement in C++
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) is like a sequence of if statements that compares a single integer value against several constant alternatives
B) is a compound statement that tests all branches against different variables
C) makes the break statement optional
D) requires compound boolean expressions as alternatives

Ans: A
Title: What is a switch statement in C++?
Difficulty: Medium
Section Ref: Special Topic 3.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

32. In a switch statement, if a break statement is missing
A) The break happens at the end of each branch by default
B) The statement will not compile
C) Execution falls through the next branch until a break statement is reached
D) The default case is automatically executed

Ans: C
Title: What happens when a break statement is missing from a switch statement?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: Special Topic 3.3

33. An if statement inside another if statement is called a
A) Switch statement
B) Nested if statement
C) Break statement
D) Syntax error, since that is not permitted in C++
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: What is it called when an if statement is inside another if statement?
Difficulty: Easy
Section Ref: 3.3

34. When an if statement is nested inside another if statement, it creates the possibility of
A) An infinite loop
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The misuse of the break statement
C) Type mismatch
D) The dangling else

Ans: D
Title: What is a dangling else?
Difficulty: Easy
Section Ref: Common Error 3.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

35. What is the output of the following code snippet?
#include using namespace std;int main(){ int s1 = 20; if (s1 <= 20) { cout << "1"; } if (s1 <= 40) { cout << "2"; }
if (s1 <= 20)
{
cout << "3";
} return 0;}
A) 1
B) 2
C) 3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 123
Ans: DTitle: What is output of snippet (with three nonexclusive ifs)?Difficulty: EasySection Ref: 3.3
36. Consider a situation where multiple if else/if statements are combined into a chain to evaluate a complex condition. Which of the following reserved words is used to define the branch to be executed when none of the conditions are true?
A) if
B) else if
C) else
D) All of the above items
Ans: CTitle: Which word defines the branch to be executed when none of the conditions are true?Difficulty: EasySection Ref: 3.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
37. Consider the following code snippet:
int number = 0;cout <> number;if (number > 30) { ………. }else if (number > 20) { ………. }else if (number > 10) { ………. }else { ………. }Assuming that the user input is 40, which of the following block of statements is executed?
A) if (number > 30) { ………. }
B) else if (number > 20) { ………. }
C) else if (number > 10) { ………. }
D) else { ………. }
Ans: ATitle: Which statement (in if/else block) is executed when input is 40?Difficulty: MediumSection Ref: 3.3
38. Assuming that the user enters 60 as the input, what is the output after running the following code snippet?
int num = 0;cout <> num;if (num < 10) { cout << "Too small!"; }else if (num < 50) { cout << "Intermediate!"; }else if (num < 100) { cout << "High!"; }else { cout << "Too high!"; }
A) Too small!
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Intermediate!
C) High!
D) Too high!
Ans: CTitle: What is output of (if/else if/else if) snippet with this input?Difficulty: MediumSection Ref: 3.3
39. Assuming that a user enters 5 as the value for num, what is the output of the following code snippet?
int num = 0;cout <> num;if (num < 50) { num = num + 5; }if (num 5) { num++; }else { num–; }cout << num << endl;
A) 0
B) 9
C) 5
D) 11
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: DTitle: What is output of (if/if/if/else) snippet with this input?Difficulty: HardSection Ref: 3.3
40. Consider the following code snippet. Assuming that the user enters 20 and 12 as the two input values, what is the output of the code snippet?
int main(){ int num1 = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; cout <> num1; cout <> num2; if (num1 < num2) { num3 = num1; } else { num3 = num2; } if (num1 < num2 + 10) { num4 = num1; } else if (num1 < num2 + 20) { num5 = num1; } cout << "num1 = " << num1 << " num2 = " << num2
<< " num3 = " << num3 << " num4 = " << num4
<< " num5 = " << num5 << endl; return 0;}

A) num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0
B) num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20
C) num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20
Ans: CTitle: What is output of (if/else if/else if) snippet with two inputs?Difficulty: HardSection Ref: 3.3
41. What is the value of the price variable after the following code snippet is executed?
int price = 42;if (price 30) { price = price * 2; }if (price < 100) { price = price – 20; }
A) 42
B) 52
C) 84
D) 64
Ans: DTitle: What is value of price variable after (if/if/if) snippet is executed?Difficulty: MediumSection Ref: 3.3
42. Consider the following code snippet. Assuming that the user inputs 75 as the age, what is the output?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int age = 0;cout <> age;if (age < 10) { cout << "Child "; }if (age < 30) { cout << "Young adult "; }if (age < 70) { cout << "Old "; }if (age < 100) { cout << "Impressively old "; }
A) Impressively old
B) Child Young adult Old
C) Young adult Old
D) Child Young adult Old Impressively old

Ans: ATitle: What is output of snippet (with 4 nonexclusive ifs) with this input?Difficulty: MediumSection Ref: 3.3
43. What is the value of the magic_powers variable after executing the following code snippet?
string magic_powers = “”;int experience_level = 9;if (experience_level > 10)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
magic_powers = magic_powers + “Golden sword “;
}if (experience_level > 8)
{
magic_powers = magic_powers + “Shining lantern “;
}if (experience_level > 2)
{
magic_powers = magic_powers + “Magic beans “;
}

A) Golden sword Shining lantern Magic beans
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Shining lantern Magic beans
C) Magic beans
D) An empty string
Ans: BTitle: What is value of variable after (if/if/if) snippet is executed?Difficulty: MediumSection Ref: 3.3
44. Assuming that a user enters 5 as the age, what is the output of the following code snippet?
int age = 0;cout <> age;if (age < 10) { cout << "Kid" << endl; }if (age < 30) { cout << "Young" << endl; }if (age < 70) { cout << "Aged" << endl; }if (age < 100) { cout << "Old" << endl; }

A) Kid
B) Kid
Young
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Kid
YoungAged
D) Kid
YoungAgedOld
Ans: DTitle: What is output of (if/if/if/if) snippet with this input?Difficulty: HardSection Ref: 3.3

45. When drawing flowcharts, unconstrained branching and merging can lead to
A) So-called “spaghetti code”
B) A better design
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Intuitive understanding of the flow of control
D) Clear visualization of the problem solution

Ans: A
Title: What does unconstrained branching and merging produce when drawing flowcharts?
Difficulty: Easy
Section Ref: 3.5

46. The flow chart shows the order in which steps should be executed, and the diamond-shaped boxes indicate
A) input
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) algorithms
C) tasks
D) conditional tests

Ans: D
Title: What do the diamond-shaped boxes indicate in a flow chart?
Difficulty: Easy
Section Ref: 3.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

47. When testing code for correctness, it always makes sense to
A) Test all cases
B) Identify boundary cases and test them
C) Check all cases by hand
D) Assume invalid input will never occur

Ans: B
Title: What is reasonable for checking / testing code?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 3.6

48. Which of the following variables is used to store a condition that can be either true or false?
A) Algebraic
B) Logical
C) Boolean
D) Conditional
Ans: CTitle: Which kind of variable is used to store a true/false condition?Difficulty: EasySection Ref: 3.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
49. Consider the following code snippet:
bool attendance = true;bool failed = false;Which of the following if statements includes a condition that evaluates to true?

A) if (attendance == “true”) { … }
B) if (attendance) { … }
C) if (failed) { … }
D) if (attendance == failed) { … }
Ans: BTitle: Which if statement includes a condition that evaluates to true?Difficulty: MediumSection Ref: 3.3
50. What is the output of the following code snippet?
int main(){ bool attendance = false; string str = “Unknown”; attendance = !(attendance); if (!attendance) { str = “False”; } if (attendance) { attendance = false; } if (attendance) { str = “True”; } else { str = “Maybe”; } cout << str << endl; return 0;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) False
B) True
C) Unknown
D) Maybe
Ans: DTitle: What is the output of snippet (with if/else and Boolean not)?Difficulty: MediumSection Ref: 3.7
51. Which of the following operators is used to combine two Boolean conditions?
A) ##
B) $$
C) %%
D) &&
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: Which operator is used to combine two Boolean conditions?Difficulty: EasySection Ref: 3.7
52. Assuming that a user enters 56 as his age, what is the output of the following code snippet?
int main(){ int age = 0; cout <> age; if (age < 13) { cout << "Kid!" <= 13 && age < 19) { cout << "Teen!" <= 19 && age < 30) { cout << "Young!" <= 30 && age < 50) { cout << "Adult!" <= 50) { cout << "Old!" << endl; } return 1;}
A) Teen
B) Young
C) Adult
D) Old
Ans: DTitle: What is output of (if with Boolean and) snippet with this input?Difficulty: MediumSection Ref: 3.7
53. Which of the following expressions represents a legal way of checking whether a value assigned to the num variable falls between 100 and 200?
A) if (num >= 200 && num <= 100)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) if (num >= 100 && num <= 200)
C) if (num >= 100 || num <= 200)
D) if (num >= 200 || num <= 100)
Ans: BTitle: Which expression checks whether a value falls between 100 and 200?Difficulty: MediumSection Ref: 3.7
54. Which of the following expressions represents a legal way of checking whether a value for the num variable is either less than 100 or more than 200?
A) if (num = 200)
B) if (num 200)
C) if (num 200)
D) if (num = 200)
Ans: CTitle: Which expression checks whether a value is less than 100 or more than 200?Difficulty: MediumSection Ref: 3.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
55. Assuming that a user enters 64 as his score, what is the output of the following code snippet?
int main(){ int score = 0; cout <> score; if (score < 40) { cout << "F" <= 40 || score < 50) { cout << "D" <= 50 || score < 60) { cout << "C" <= 60 || score < 70) { cout << "B" <= 70 || score < 80) { cout << "B+" << endl; } else { cout << "A" << endl; } return 0;
}
A) D
B) C
C) B
D) A
Ans: ATitle: What is output of (if/else if with Boolean or) with this input?Difficulty: HardSection Ref: 3.7
56. What is the output of the following code snippet?
int main(){ int num = 100; if (num > 100); { num = num – 10; } cout << num << endl; return 0;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 90
B) 100
C) 99
D) 101

Ans: ATitle: What is output of (if with > condition) with this input?Difficulty: MediumSection Ref: 3.1
57. Which of the following operators is used to invert a conditional statement?
A) !
B) !=
C) ||
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) ?
Ans: ATitle: Which operator is used to invert a conditional statement?Difficulty: EasySection Ref: 3.7
58. Which of the following operators is NOT a relational operator?
A) <=
B) +=
C) !=
D) ==
Ans: BTitle: Which operator is NOT a relational operator?Difficulty: EasySection Ref: 3.2
59. What is the output of the following code snippet?
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{ const int MIN_SPEED = 45; const int MAX_SPEED = 65; int speed = 55; if (!(speed MIN_SPEED)) { speed = speed + 10; } cout << speed; return 0;}
A) 45
B) 55
C) 65
D) 50
Ans: BTitle: What is output of (if with Boolean not) snippet?Difficulty: Medium
Section Ref: 3.7

60. What is the value of num after you run the following code snippet?
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{ int num = 100; if (num <= 100) { num++; } if (num <= 200) { num–; } if (num <= 300) { num++; } if (num <= 400) { num–; } if (num <= 500) { num++; } return 0;}
A) 99
B) 100
C) 101
D) 102
Ans: CTitle: What is value of variable after snippet (with five nonexclusive ifs)?Difficulty: HardSection Ref: 3.3
61. Which of the following options correctly represents a “nested if” structure?
A) if (cost < 70)
{ if (tax_rate < 0.10) { … }}
B) if (cost < 70) { … }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
if (tax_rate < 0.10) { … }
C) if (cost < 70) { … }
else { . . . }if (tax_rate < 0.10) { … }}
D) if (cost < 70)
{ else { if (tax_rate < 0.10) { … } }}
Ans: ATitle: Which snippet represents a “nested if” structure?Difficulty: EasySection Ref: 3.4
62. Which of the following statements is true about the “nested if” structure?
A) It cannot have any else branches at all.
B) It allows multiple else branches in a single if statement.
C) It allows one if statement within another if statement.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) It does not allow multiple else branches inside a nested if statement.
Ans: CTitle: Which statement is true about the “nested if” structure?Difficulty: EasySection Ref: 3.4
63. Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet?
int main(){ int num1; int num2; int num3 = 0; cout <> num1; cout <> num2; cout <> num3; if (num1 > num2) { if (num1 > num3) { cout << num1 << endl; } else { cout << num3 < num3) { cout << num2 << endl; } else { cout << num3 << endl; } } return 0;}
A) 0
B) 10
C) 20
D) 30
Ans: DTitle: What is output of (if/else with nested if/else) snippet with these three inputs?Difficulty: MediumSection Ref: 3.4
64. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main(){ int num = 100; if (num < 100) { if (num < 50) { num = num – 5; } else { num = num – 10;
} } else { if (num > 150) { num = num + 5; } else { num = num + 10; } } cout << num << endl; return 0;}
A) 95
B) 100
C) 105
D) 110
Ans: DTitle: What is output of (if/else with nested if/else) snippet?Difficulty: HardSection Ref: 3.4
65. Which of the following options refers to the technique of simulating program execution on a sheet of paper?
A) Compiling
B) Prototyping
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Tracing
D) Debugging
Ans: CTitle: Which refers to the technique of simulating program execution on a sheet of paper?Difficulty: EasySection Ref: 3.4
66. Which of the following coding techniques can hand-tracing be applied to?
A) Pseudocode
B) C++ code
C) Both Pseudocode and C++ code
D) Neither Pseudocode nor C++ code

Ans: CTitle: Which coding technique can hand-tracing be applied to?Difficulty: EasySection Ref: 3.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
67. Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet?
int price = 0;string status = “”;cout <> price;if (price >= 50){ status = “reasonable”; if (price >= 75) { status = “costly”; }}else{ status = “inexpensive”; if (price <= 25) { status = "reasonable"; }
}
A) price status
0 “”
22 “inexpensive”
“reasonable”
B) price status
0 “inexpensive”
22 “reasonable”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) price status
0 “”
22 “reasonable”
“costly”
D) price status
0 “reasonable”
22 “costly”

Ans: ATitle: Which hand trace table is valid for this snippet?Difficulty: MediumSection Ref: 3.4
68. Which of the following operators compare using short-circuit evaluation?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) ++
B) –
C) &&
D) ==

Ans: CTitle: Which operator uses short-circuit evaluation?Difficulty: EasySection Ref: Special Topic 3.4
69. Consider the following code snippet:
int score = 0;double price = 100;if (score > 0 && price 10)
{ cout << "buy" << endl;}Which of the following statements is true on the basis of this code snippet?
A) The output is buy.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The code snippet compiles and runs, but there is no output.
C) The code snippet doesn’t compile.
D) The code snippet causes a divide-by-zero error.

Ans: BTitle: Which statement is true on the basis of this code snippet?Difficulty: MediumSection Ref: Special Topic 3.4

70. Which of the following options checks that city is neither Chicago nor Dallas?
A) if (city != “Chicago” || city != “Dallas”)
B) if !(city == “Chicago” || city == “Dallas”)
C) if !(city == “Chicago” && city == “Dallas”)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) if (city != “Chicago” || city == “Dallas”)
Ans: BTitle: Which option checks that city is neither Chicago nor Dallas?Difficulty: MediumSection Ref: 3.7
71. Assuming that a user enters 45, 78, and 12 one after another, separated by spaces, what is the output of the following code snippet?
int main(){ int num1; int num2; int num3 = 0; cout <> num1; cout <> num2; cout <> num3; if (!(num1 > num2 && num1 > num3)) { cout << num1 < num1 && num2 > num3)) { cout << num2 < num1 && num3 > num2)) { cout << num3 << endl; } return 0;}
A) 12
B) 45
C) 78
D) There is no output due to compilation errors.
Ans: BTitle: What is output of (if/else if/else if) snippet with these three inputs?Difficulty: HardSection Ref: 3.7
72. Which of the following statements can be used to validate that the user input for the floor variable is between 0 and 20?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) if (floor >= 0 && floor <= 20)
B) if (floor >= 0 || floor <= 20)
C) if (floor = 20)
D) if (floor = 20)

Ans: ATitle: Which statement validates that input is between 0 and 20?Difficulty: EasySection Ref: 3.8
73. Assuming that the valid price value should be between 30 and 50, does the following code snippet test this condition correctly?
int main(){ const int MIN_PRICE = 30; const int MAX_PRICE = 50; int price = 0; cout <> price; if (price < MIN_PRICE) { cout < MAX_PRICE) { cout << "Error: The price is too high."; } else { cout << "The price entered is in the valid price range."; }
return 0;}
A) This code snippet ensures that the price value is between 30 and 50.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) This code snippet only ensures that the price value is greater than 30.
C) This code snippet only ensures that the price value is less than 50.
D) This code snippet ensures that the price value is either less than 30 or greater than 50.

Ans: ATitle: Does this code test whether input is between 30 and 50?Difficulty: MediumSection Ref: 3.8
74. Which of the following conditions tests for the failure of the user to assign an integer value to the floor variable?
int floor;cout <> floor;
A) if (fail(floor))
B) if (cin.fail())
C) if (cin.fail)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) if (floor < 0)
Ans: BTitle: Which condition tests for (failed user input)?Difficulty: EasySection Ref: 3.8
75. Assuming that the user inputs “twenty” as the input, what is the output of the following code snippet?
int main(){ int age = 0; cout <> age; if (cin.fail()) { cout << "Invalid Data!" << endl; return 0; } if (age < 18) { cout << "You are not eligible to vote!"; return 0; } else { cout << "You are a valid voter!" < 60) { cout << "You are a senior voter!" << endl; } else { cout << "You are not a senior voter!" << endl; } }
return 0;
}
A) You are not eligible to vote!
B) You are a valid voter!
C) You are a valid voter!
You are a senior voter!
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Invalid Data!
Ans: DTitle: What is output of (if/else with test for failed input) snippet with this input?Difficulty: MediumSection Ref: 3.6
76. Assuming that the user provides 303 as input, what is the output of the following code snippet?
int x;
int y;x = 0;cout <> y;if (y > 300) { x = y; }else { x = 0; }cout << "x: " << x << endl;
A) x: 0
B) x: 300
C) x: 303
D) There is no output due to compilation errors.
Ans: CTitle: What is output of (if/else with > test) snippet with this input?Difficulty: HardSection Ref: 3.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
77. Assuming that the user provides 49 as input, what is the output of the following code snippet?
int x;
int y;x = 0;cout <> y;if (y > 50);{ x = y;}cout << "x: " << x << endl;
A) x: 0
B) x: 49
C) x: 50
D) There is no output due to compilation errors.
Ans: ATitle: What is output of (if with > test) snippet with this input?Difficulty: HardSection Ref: 3.2

78. Assuming that a user enters 25 as input, what is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main(){ int age; cout <> age; if (age > 30) { cout << "You are wise!" << endl; } else { cout << "You have much to learn!" << endl; } return 0;}
A) There is no output due to compilation errors.
B) You are wise!
C) You have much to learn!
D) You are wise!
You have much to learn!
Ans: CTitle: What is output of (if/else with > test) with this input?Difficulty: MediumSection Ref: 3.2

79. What is the output of the following code snippet, if the input is 50?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include using namespace std;int main(){ int x; cout <> x; if (x > 100) { x++; } else { x–; } cout << x << endl; return 0;}
A) 49
B) 50
C) 51
D) 52
Ans: ATitle: What is output of (if/else with increment/decrement) with this input?Difficulty: MediumSection Ref: 3.2

80. A store applies a 15% service charge on all items with a price of at least $150. No service charge is otherwise applicable. Which of the following statements DOES NOT correctly compute the service charge?
A) double service_charge = 0; if (cost >= 150) { service_charge = 0.15 * cost; }
B) double service_charge = 0.15 * cost; if (cost <= 150) { service_charge = 0; }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) double service_charge; if (cost < 150) { service_charge = 0; } else { service_charge = 0.15 * cost; }
D) double service_charge = 15; if (cost >= 150) service_charge = 0.15 * cost; else service_charge = 0;
Ans: BTitle: Which statement DOES NOT correctly compute the service charge?Difficulty: EasySection Ref: 3.2

81. What is the output of the following code snippet?
int main()
{ double salary = 55000; double cut_off = 65000; double min_salary = 40000; if (min_salary > salary) { cout << "Minimum salary requirement is not met." << endl; } if (cut_off < salary) { cout << "Maximum salary limit is exceeded." << endl; } else { cout << "Salary requirement is met." << endl; } return 0;}
A) Minimum salary requirement is not met.
B) Maximum salary limit is exceeded.
C) Salary requirement is met.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) There is no output.
Ans: CTitle: What is output of (if/if/else) snippet?Difficulty: MediumSection Ref: 3.2

82. What is the output of the following code snippet?
int main(){ int digit = 500; if (digit != 500) { cout << "500" << endl; } else { cout << "Not 500" << endl; } return 0;}
A) There is no output due to compilation errors.
B) 500
C) Not 500
D) 500
Not 500
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: CTitle: What is output of (if/else with != test)?Difficulty: HardSection Ref: 3.2

83. What is the output of the following code snippet?
#include #include using namespace std;int main(){ string some_string1 = “his”; string some_string2 = “cycle”; if (some_string1 < some_string2) { cout << some_string2; } else { cout << some_string1; } return 0;}
A) his
B) hiscycle
C) cycle
D) There is no output due to compilation errors.
Ans: ATitle: What is output of (if/else with string ordering test)?Difficulty: MediumSection Ref: 3.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

84. What is the output of the following code snippet?
#include using namespace std;int main(){ int num1 = 40; if (num1 <= 40) { cout << "F"; } if (num1 <= 75) { cout << "C"; }
if (num1 <= 90)
{ cout << "B"; } return 0;}
A) F
B) C
C) B
D) FCB
Ans: DTitle: What is output of snippet (with three nonexclusive ifs)?Difficulty: EasySection Ref: 3.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

85. Assuming that the user enters 600 as the input, what is the output after running the following code snippet?
int number = 0;cout <> number;if (number < 200) { cout << "Low spender"; }else if (number < 500) { cout << "Spending in moderation"; }else if (number < 1000) { cout << "Above average!"; }else { cout << "High Roller!"; }
A) Low spender
B) Spending in moderation
C) Above average!
D) High Roller!
Ans: CTitle: What is output of (if/else if/else if) snippet with this input?Difficulty: MediumSection Ref: 3.3

86. Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int x = 0;cout <> x;if (x < 100) { x = x + 5; }if (x 10) { x++; }else { x–; }cout << x << endl;
A) 27
B) 28
C) 29
D) 30

Ans: CTitle: What is output of (if/if/if/else) snippet with this input?Difficulty: HardSection Ref: 3.3

87. What is the value of the cost variable after the following code snippet is executed?
int cost = 82;if (cost 50) { cost = cost * 2; }if (cost < 100) { cost = cost – 20; }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 82
B) 92
C) 184
D) 164
Ans: CTitle: What is value of cost variable after (if/if/if) snippet is executed?Difficulty: MediumSection Ref: 3.3

88. Consider the following code snippet. Assuming that the user inputs 68 as the score, what is the output?
int score = 0;cout <> score;if (score < 50) { cout << "You need to practice!"; }if (score < 100) { cout << "Almost respectable!"; }if (score < 150) { cout << "You hit triple digits!"; }if (score < 250) { cout << "Impressive!"; }
A) You need to practice!
B) Almost respectable !You hit triple digits!
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) You hit triple digits !Impressive!
D) Almost respectable !You hit triple digits !Impressive!

Ans: DTitle: What is output of snippet (with 4 nonexclusive ifs) with this input?Difficulty: MediumSection Ref: 3.3

89. Assuming that a user enters 8 as the shoe size, what is the output of the following code snippet?
int shoe_size = 0;cout <> shoe_size;if (shoe_size < 6) { cout << "Petite" << endl; }if (shoe_size < 8) { cout << "Small" << endl; }if (shoe_size < 10) { cout << "Medium" << endl; }
if (shoe_size < 14) { cout << "Large" << endl; }
A) Petite
B) Petite
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Small
C) Small
Medium
D) Medium
Large
Ans: DTitle: What is output of (if/if/if/if) snippet with this input?Difficulty: HardSection Ref: 3.3

90. Consider the following code snippet:
bool married = true;bool engaged = false;Which of the following if statements includes a condition that evaluates to true?
A) if (married == “true”) { … }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) if (married) { … }
C) if (engaged) { … }
D) if (married == engaged) { … }
Ans: BTitle: Which if statement includes a condition that evaluates to true?Difficulty: MediumSection Ref: 3.4

91. What is the output of the following code snippet?
int main(){ bool passed = false; string some_str = “Unknown”; passed = !(passed); if (!passed) { some_str = “False”; } if (passed) { passed = false; } if (!passed) { some_str = “True”; } else { some_str = “Maybe”; } cout << some_str << endl; return 0;}
A) False
B) True
C) Unknown
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Maybe
Ans: BTitle: What is the output of snippet (with if/else and Boolean not)?Difficulty: MediumSection Ref: 3.4

92. Assuming that a user enters 64 as his golf score, what is the output of the following code snippet?
int main(){ int golf_score = 0; cout <> golf_score; if (golf_score < 60) { cout << "Astounding!" <= 60 && golf_score < 70)
{
cout << "Professional!" << endl;
} if (golf_score >= 70 && golf_score < 80)
{
cout << "Pretty good!" << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
} if (golf_score >= 80 && golf_score < 90)
{
cout << "Not so hot!" << endl;
} if (golf_score >= 90)
{
cout << "Keep your day job!" << endl;
} return 0;}
A) Astounding!
B) Professional!
C) Pretty good!
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Keep your day job!
Ans: BTitle: What is output of (if with Boolean and) snippet with this input?Difficulty: MediumSection Ref: 3.3

93. Which of the following expressions represents a legal way of checking whether a value assigned to the number variable falls between 50 and 100?
A) if (number >= 100 && number <= 50)
B) if (number >= 50 && number <= 100)
C) if (number >= 50 || number <= 100)
D) if (number >= 100 || number <= 50)
Ans: BTitle: Which expression checks whether a value falls between 50 and 100?Difficulty: MediumSection Ref: 3.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
94. Assuming that a user enters 68 as his score, what is the output of the following code snippet?
int main(){ int score = 0; cout <> score; if (score < 50) { cout << "F" <= 50 || score < 55) { cout << "D" <= 55 || score < 65) { cout << "C" <= 65 || score < 75) { cout << "B" <= 75 || score < 80) { cout << "B+" << endl; } else { cout << "A" << endl; } return 0;}
A) D
B) C
C) B
D) A
Ans: ATitle: What is output of (if/else if with Boolean or) with this input?Difficulty: HardSection Ref: 3.7
95. Assuming that a user enters 50, 70, and 60 as input values one after another, separated by spaces, what is the output of the following code snippet?
int main(){ int number1; int number2; int number3 = 0; cout <> number1; cout <> number2; cout <> number3; if (number1 > number2) { if (number1 > number3) { cout << number1 << endl; } else { cout << number3 < number3) { cout << number2 << endl; } else { cout << number3 << endl; } } return 0;}
A) 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 50
C) 60
D) 70
Ans: DTitle: What is output of (if/else with nested if/else) snippet with these three inputs?Difficulty: MediumSection Ref: 3.4

96. Assuming that a user enters 45 as the brightness of a lamp, which of the following hand-trace tables is valid for the given code snippet?
int brightness = 0;string description = “”;cout <> brightness;if (brightness >= 120){ description = “very bright”; if (brightness >= 100) { description = “bright”; }}else{ description = “pleasant”; if (brightness <= 50) { description = "dim"; }}
A) brightness description
0 “”
45 “pleasant”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
“dim”
B) brightness description
0 “very bright”
45 “bright”
C) brightness description
0 “”
45 “bright”
“pleasant”
D) brightness description
0 “bright”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
45 “pleasant”
Ans: ATitle: Which hand-trace table is valid for this snippet?Difficulty: MediumSection Ref: 3.4

97. Which of the following options checks that country is neither China nor Denmark?
A) if (country != “China” || country != “Denmark”)
B) if !(country == “China” || country == “Denmark”)
C) if !(country == “China” && country == “Denmark”)
D) if (country != “China” || country == “Denmark”)

Ans: BTitle: Which option checks that country is neither China nor Denmark?Difficulty: MediumSection Ref: 3.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
98. Assuming that the valid cost should be between 100 and 200, does the following code snippet test this condition correctly?
int main(){ const int MIN_COST = 100; const int MAX_COST = 200; int cost = 0; cout <> cost; if (cost < MIN_COST) { cout < MAX_COST) { cout << "Error: The cost is too high."; } else { cout << "The cost entered is in the valid cost range."; }
return 0;}
A) This code snippet ensures that the cost value is between 100 and 200.
B) This code snippet only ensures that the cost value is greater than 100.
C) This code snippet only ensures that the cost value is less than 200.
D) This code snippet ensures that the cost value is either less than 100 or greater than 200.

Ans: ATitle: Does this code test whether input is between 100 and 200?Difficulty: MediumSection Ref: 3.8

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
99. Which of the following conditions tests for the failure of the user to assign an integer value to the number variable?
int number;cout <> number;
A) if (fail(number))
B) if (cin.fail())
C) if (cin.fail)
D) if (number < 0)
Ans: BTitle: Which condition tests for (failed user input)?Difficulty: EasySection Ref: 3.8

100. Assuming that the user inputs “twenty” as the input, what is the output of the following code snippet?
int num_employees = 0;cout <> num_employees;if (cin.fail()){ cout << "Invalid Data!" << endl; return 0;}if (num_employees < 10){ cout << "Very small business!"; return 0;}else{ cout << "Small business" < 100) { cout << "Mid size business" << endl; } else { cout << "Large business" << endl; } return 0;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Very small business
B) Small business
C) Mid size business!
Large business
D) Invalid Data!
Ans: DTitle: What is output of (if/else with test for failed input) snippet with this input?Difficulty: MediumSection Ref: 3.8

1. Which of the following loops executes the statements inside the loop before checking the condition?
A) for
B) while
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) do-while
D) None of the listed items

Ans: CTitle: Which loop executes before checking condition?Difficulty: EasySection Ref: 4.4

2. The process of hand tracing code is valuable because
A) It is usually faster than just running the code.
B) It is the best way to design an algorithm.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) You must already have a working program in order to do it.
D) It gives valuable insight that you do not get by running the code.

Ans: D
Title: Why is hand tracing valuable?
Difficulty: EasySection Ref: 4.2

3. When hand-tracing the loop in the code snippet below, which variables are important to evaluate?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i = 10;
int j = 5;
int k = -10;
int sum = 0;
while (i > 0)
{
sum += i + j;
i–;
cout << “Iteration: ” << i << endl;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) The variables i and j
B) The variables i and sum
C) The variables i, j, and k
D) The variables j and k

Ans: B
Title: Which variables are important to monitor when hand-tracing a code snippet?
Difficulty: EasySection Ref: 4.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

4. When hand tracing, drawing a line through the value stored in a variable means that
A) The value stored there has changed to something new
B) The variable is the wrong data type for the code being executed
C) The expression being evaluated uses that variable
D) The variable must be inside a loop

Ans: A
Title: What does it mean to draw a line through values when hand-tracing?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: MediumSection Ref: 4.2

5. When hand-tracing a portion of code, which statement about Boolean conditions is true?
A) They typically are too complex to be evaluated
B) They do not need to be monitored since their result usually is not stored in a variable
C) It is rare to encounter a Boolean condition
D) They are crucial to evaluate since they determine if-statement conditions and looping

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: Which statement about Boolean conditions is true?
Difficulty: MediumSection Ref: 4.2

6. Storyboards are a helpful part of the design process because the storyboard develops
A) A pseudocode description of the algorithm being designed
B) The mathematical formulas required for computing a correct answer
C) What information is needed to solve the problem, and how to present that information
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The amount of time and space it will require to find a solution

Ans: C
Title: What is the role of the storyboard?Difficulty: EasySection Ref: 4.6

7. When designing storyboards, it is a good idea to use different colors to
A) Make it easy to distinguish between user input and program output
B) Match the colors your program will use when it is finally designed
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Emphasize the difference between numbers and words
D) Draw lines to divide up panels into different regions

Ans: A
Title: What is the role of colors when designing using storyboards?
Difficulty: EasySection Ref: 4.6

8. Suppose you must design a program to calculate the roll-out (number of inches traveled in one revolution of the pedals) of a bicycle based on its gear combinations. The user must provide the gear sizes, which must be converted into roll-out for all different gear combinations. How can the flow of user interaction for this problem be designed?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Hand-tracing can confirm code that implements gear selection
B) Pseudocode can guide algorithm design through divide-and-conquer strategy
C) A storyboard can be used
D) The physical gears can lead to ideas for the correct algorithm to use

Ans: C
Title: How can user interaction be designed for an example problem?
Difficulty: MediumSection Ref: 4.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

9. Which statement about storyboards is true?
A) A storyboard can help prevent potential user confusion early in the design process
B) Storyboards are used primarily to understand how implemented programs work
C) The storyboard helps to train users about how to use software
D) Storyboards have no relationship to the structure of an actual working program

Ans: A
Title: Which statement about storyboards is true?
Difficulty: MediumSection Ref: 4.6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

10. Which common error is present in the code below, which is intended to calculate the average value from a sum of numbers?
double total;
int n;
double input;
while (cin >> input)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
total = total + input;
n++;
}
if (n != 0)
{
double average = total / n;
}
A) Uninitialized variables
B) Infinite loop
C) Type mismatch
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Division by zero

Ans: A
Title: What is the pitfall in the code snippet?
Difficulty: EasySection Ref: 4.7

11. Which common error is present in the code below, which is intended to calculate the average value from a sum of numbers?
double total = 0.0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int n = 0;
double input;
while (cin >> input)
{
total = total + input;
n++;
}
double average = total / n;
A) Uninitialized variables
B) Infinite loop
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Type mismatch
D) Division by zero

Ans: D
Title: What is the pitfall in the code snippet?
Difficulty: EasySection Ref: 4.7

12. Which line of code should replace the placeholder symbols ? ? ? to count correctly the number of integers among the inputs that are less than 100?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int count = 0;
int input;
while (cin >> input)
{
if (input < 100)
{
? ? ?
}
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) input += count;
B) input++;
C) count++;
D) count += input;

Ans: C
Title: Which line of code correctly completes the code snippet?
Difficulty: EasySection Ref: 4.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

13. Which line of code should replace the placeholder symbols ? ? ? in order to terminate the loop when the first grade greater than or equal to 90 is encountered?
int count = 0;
bool found = false;
int grade;
while (!found && (cin >> grade))
{
? ? ?
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
? ? ?
}
else { count++ };
}

A) if (grade >= 90)
{
found = true;
}
B) if (grade >= 90)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
count–;
}
C) if (grade <= 90)
{
found = true;
}
D) if (grade => 90)
{
found = true;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

Ans: A
Title: Which line(s) of code correctly complete the code snippet?
Difficulty: EasySection Ref: 4.7

14. What is calculated by the code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int n = 0;
int x;
while (cin >> x)
{
if (x > n)
{
n = x;
}
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The average of the input values
B) The number of input values
C) The minimum value of all input values
D) The maximum value of all input values

Ans: D
Title: What is calculated by the code snippet?
Difficulty: EasySection Ref: 4.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

15. What is calculated by the code snippet?
int n = 0;
int x;
while (cin >> x)
{
if (x == n)
{
n++;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) The number of values that are positive
B) The number of values that are equal to zero
C) The minimum value of all the input values
D) The maximum value of all the input values

Ans: B
Title: What is calculated by the code snippet?
Difficulty: MediumSection Ref: 4.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

16. Assuming variables have been declared as follows, which code snippet will halt when two successive input values are zero?
int n = 0;
int u = 0;
int x;
bool found = false;

A) cin >> u;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (!found && (cin >> x))
{
if ((x == 0) && (n == 0)) { found = true; }
{
n++;
}
}
B) cin >> u;
while (!found && (cin >> x))
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
if ((x == 0) && (u == 0)) { found = true; }
u = x;
}

C) while (!found && (cin >> x))
{
if ((x == 0) && (u == 0)) { found = true; }
u = x;
}
D) while (!found && (cin >> x))
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
if ((x != 0) && (u != 0)) { found = false; }
cin >> u;
}

Ans: B
Title: Which code snippet for finding successive values equal to zero is correct?
Difficulty: MediumSection Ref: 4.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

17. What is calculated by the code snippet?
int n = 0;
int x;
while (cin >> x)
{
if (x < 0)
{
n = n + x;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) The number of values that are negative
B) The sum of values that are negative
C) The minimum value of all the input values
D) The maximum value of all the input values

Ans: B
Title: What is calculated by the code snippet?
Difficulty: MediumSection Ref: 4.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

18. Which statement will generate a random number between -1 and 4 (inclusive), given this statement which generates a random floating point number between 0 and 1:
double r = rand() * 1.0 / RAND_MAX; // Between 0 and 1
A) double x = -1 + 2 * r;
B) double x = -1 + 3 * r;
C) double x = -1 + 4 * r;
D) double x = -1 + 5 * r;

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement generates a random number within the required interval?
Difficulty: MediumSection Ref: 4.9

19. Which statement will correctly compute random integers between integer values a and b?
A) int r = rand() % (b – a + 1) + a;
B) int r = rand() % (a – b + 1) + a;
C) int r = rand() % (b – a – 1) + a;
D) int r = rand() % (b – a + 1) – a;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: Which statement generates a random number within the required interval?
Difficulty: MediumSection Ref: 4.9

20. The Monte Carlo method can find solutions to problems that are difficult to solve precisely. A typical example of such a problem is
A) The solution to the quadratic equation (y = ax2 + bx + c)
B) The simulation of multi-sided dice being thrown
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The approximation of the value of pi
D) Security algorithms to stop software piracy

Ans: C
Title: What is a typical example of a problem to which the Monte Carlo method might be applied?
Difficulty: MediumSection Ref: 4.9

21. How many times will the following loop run?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i = 0;while (i < 9){ cout << i << endl; i++;}
A) 0
B) 8
C) 9
D) 10
Ans: CTitle: How many iterations of while loop?Difficulty: EasySection Ref: 4.1
22. What will be the result of running the following code fragment?
int time = 0;int year = 0;int rate = 0;int principal = 1000;int interest = 0;while (year < 10){ interest = (principal * time * rate) / 100; cout << interest << endl;}
A) The code fragment will display the interest calculated for nine years.
B) The code fragment will not display the calculated interest and halt abruptly.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The code fragment will not display any output because it will not compile.
D) The code fragment will continue to display the calculated interest because the loop will never end.

Ans: DTitle: What is result of while loop?Difficulty: EasySection Ref: 4.1
23. What is the output of the code snippet given below?
int i = 0;while (i != 9){ cout << i << " "; i = i + 2;}
A) No output
B) 0 2 4 6 8
C) 10 12 14 16 18 …. (infinite loop)
D) 0 2 4 6 8 10 12 14 …. (infinite loop)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is output of while loop?Difficulty: MediumSection Ref: 4.1

24. How many times does the code snippet given below display “Monster Mash”?
int count = 0;while (count != 9){ cout << "Monster Mash" << endl;
if ((count % 2) == 0) {
count++;
}
else
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
count–;
}
}
A) Infinite times
B) 8 times
C) 9 times
D) 10 times
Ans: ATitle: How many iterations of while loop?Difficulty: MediumSection Ref: 4.1
25. How many times does the code snippet given below display “Loop Execution”?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i = 0;while (i != 9){ cout << "Loop Execution" << endl; i++;}
A) Infinite times
B) 8 times
C) 9 times
D) 10 times
Ans: CTitle: How many iterations of while loop?Difficulty: MediumSection Ref: 4.1
26. What is the output of the code fragment given below?
int i = 0;int j = 0;while (i < 25){ i = i + 2; j++;}cout << j << endl;
A) 0
B) 12
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 13
D) The code fragment displays no output because it does not compile.
Ans: C
Title: What is output of while loop?Difficulty: MediumSection Ref: 4.1
27. Which of the following code snippets displays the output exactly 10 times?
A) int i = 0;
while (i < 10);{ cout << "This is example 1." << endl; i++;}
B) int i = 0;
while (i < 10){ cout << "This is example 2." << endl; i++;}
C) int i = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (i < 10){ cout << "This is example 3." << endl;};
D) int i = 0;
while (i < 10);{ cout << "This is example 4." << endl; i++;};
Ans: B
Title: Which while loop executes 10 times?Difficulty: MediumSection Ref: 4.1
28. What is the output of the following code snippet?
int i = 1;while (i < 10){ cout << i << " "; i = i + 2; if (i == 5) { i = 9; }}
A) 1 3 5
B) 1 3 9
C) 1 3 5 7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 1 3 5 9
Ans: BTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
29. What is the output of the following code snippet?
int i = 1;while (i != 9){ cout << i << " "; i++; if (i = 9) { cout << "End"; }}
A) 1 End
B) 1 End (infinite loop)
C) 1 2 3 4 5 6 7 8 End
D) 1 2 3 4 5 6 7 8 End (infinite loop)
Ans: A
Title: What is output of while loop?Difficulty: HardSection Ref: 4.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
30. The code snippet below checks whether a given number is a prime number.
int main(){ int j = 2; int result = 0; int number = 0; cout <> number; while (j <= number / 2) { if (number % j == 0) { result = 1; } j++; } if (result == 1) { cout << "Number: " << number << " is Not Prime! "; } else { cout << "Number: " << number << " is Prime! "; } return 0;}What will be the result of executing this code snippet?
A) The code snippet will not compile.
B) The code snippet will display the desired result without errors
C) The code snippet will display the desired result even though there is a logic error
D) The code snippet will not display the desired result
Ans: BTitle: Will while loop with if/else produce desired result?Difficulty: HardSection Ref: 4.1
31. What are the values of i and j obtained after the following code fragment is run?
int i = 60;int j = 50;int count = 0;while (count < 5){ i = i + i; i = i + 1; j = j – 1; j = j – j; count++;}cout << i<< endl << j;
A) i = 65, j = 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) i = 65, j = 45
C) i = 1951, j = 0
D) i = 1951, j = 45
Ans: CTitle: What are values of variables after while loop executes? Difficulty: HardSection Ref: 4.2
32. Which error type is an off-by-one error?
A) Run-time error
B) Compile-time error
C) Syntax error
D) Data type mismatch
Ans: ATitle: What type of error is an off-by-one error?Difficulty: EasySection Ref: 4.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
33. How many times does the following code fragment display “Hello World”?
int i = 10;while (i >= 0){ cout << "Hello World" << endl; i–;}
A) 9 times
B) 10 times
C) 11 times
D) Infinite times

Ans: CTitle: How many times does while loop execute?Difficulty: EasySection Ref: 4.1
34. What changes do you need to make in the following code snippet to display “Let us C” exactly 10 times?
int i = 0;while (i <= 10){ cout << "Let us C" << endl; i++;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) int i = 1;
B) while (i < 9)
C) while (i < 11)
D) No change required
Ans: ATitle: What changes needed so while loop executes 10 times?Difficulty: EasySection Ref: 4.1
35. What is the output of the following code fragment?
int i = 1;int sum = 0;while (i <= 11){ sum = sum + i; i++;}cout << "The value of sum is " << sum;
A) The value of sum is 0
B) The value of sum is 45
C) The value of sum is 55
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The value of sum is 66
Ans: DTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
36. What is the output of the code snippet given below?
string s = “12345”;int i = 1;while (i < 5){ cout << s.substr (i, 1); i++;}
A) No output
B) 1234
C) 12345
D) 2345
Ans: DTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
37. How many times does the loop run in the following code fragment?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i;for (i = 0; i < 50; i = i + 4){ cout << i << endl;}
A) 1
B) 12
C) 13
D) 14

Ans: CTitle: How many times does for loop execute?Difficulty: EasySection Ref: 4.3
38. Is the code snippet written below legal?
string s = “1234”;for (int i = 0; i <= 5; i++){ cout << s.substr (i, 1);}
A) Yes.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) No; there should be a semicolon at the end of line 2.
C) No; for i = 5, s.substr (i, 1) will result in a bounds error.
D) No; line 4 should have << endl before the semicolon.
Ans: CTitle: Are there errors in for loop?Difficulty: MediumSection Ref: 4.3
39. How many times does the following loop execute?
double num;double sum = 0;for (int i = 0; i < 10; i++){ cout <> num; if (sum > num) { sum = num; } if (i == 3) { i = 8; }}
A) 0 times
B) 5 times
C) 8 times
D) 10 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: BTitle: How many times does for loop with nested if execute?Difficulty: MediumSection Ref: 4.3
40. How many times does the following code snippet display “Loop Execution”?
for (int i = 0; i < 10; i++);{ cout << "Loop Execution" << endl;}
A) Ten times.
B) The code snippet does not run because of a compile-time error.
C) The code snippet does not run because of a run-time error.
D) Only one time.
Ans: DTitle: How many times does for loop execute?Difficulty: HardSection Ref: 4.3
41. What is the output of the code snippet given below?
int i;int j = 0;for (i = 0; i < 5; i++){ if (i % 2 == 0) { i = i + 2; j++; } else { i++; j = j + 2; } j++;}cout << "i=" << i << ", j=" << j;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) i=7, j=7
B) i=7, j=6
C) i=6, j=7
D) i=5, j=5

Ans: D
Title: What is output of for loop with nested if/else?
Difficulty: HardSection Ref: 4.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
42. Which loop does not check a condition at the beginning of the loop?
A) The do-while loop
B) The while loop
C) The for loop
D) Any loop using a Boolean value
Ans: ATitle: Which loop does not check condition before executing?Difficulty: EasySection Ref: 4.4
43. How many times is the text “Let us C” printed if the code snippet given below is run?
int i = 0;do{ cout << "Let us C" << endl; i++; if (i % 2 == 0) { i = 11; }}while (i <= 10);
A) 1
B) 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 10
D) 11
Ans: BTitle: How many times does do loop with nested if execute?Difficulty: MediumSection Ref: 4.4
44. What is the output of the code snippet given below?
string s = “12345”;int i = 1;do{ if (i > 1) { cout << s.substr (i, 1); }}while (i < 5);
A) No output
B) No output (Infinite loop)
C) 12345
D) 2345
Ans: BTitle: What is output of do loop with nested if?Difficulty: MediumSection Ref: 4.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
45. What is the output of the code snippet given below?
string s = “aeiou”;int i = 0;do{ cout <= 3) { i = 5; }}while (i < 5);
A) a
B) aei
C) aeiou
D) The code snippet does not display any output.
Ans: BTitle: What is output of do loop with nested if?Difficulty: MediumSection Ref: 4.3
46. Is the following code snippet legal?
bool i = false;do{ cout << "What do you C?" << endl;}while (i != i);
A) Yes, it is legal but does not print anything.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Yes, it is legal and prints “What do you C?” once.
C) Yes, it is legal and prints “What do you C?” twice.
D) No, it is not legal and gives an error.
Ans: BTitle: Are there errors in do loop?Difficulty: HardSection Ref: 4.4
47. How many times does the following loop run?
int i = 0;int j = 1;do{ cout << i << ";" << j <= 1);
A) 0 times
B) 1 times
C) 2 times
D) 4 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: How many times does do loop with nested if execute?Difficulty: HardSection Ref: 4.4

48. A loop inside another loop is called:
A) A sentinel loop
B) A nested loop
C) A parallel loop
D) A do/while loop
Ans: BTitle: What is a loop inside another loop?Difficulty: EasySection Ref: 4.8
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

49. Which statement best describes the role of the inner loop in the following code snippet?
int i;int j;for (i = 1; i <= 3; i++){ for (j = 1; j <= 3; j++) { cout << "#"; } cout << endl;}

A) Increments the column index for the generated output
B) Increments the row index for the generated output
C) Creates a triangle shape by reducing length of each successive row by one
D) Controls white space before the “#” character is displayed

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which for loop in snippet increments the row index?
Difficulty: MediumSection Ref: 4.8

50. What will be the output of the following code snippet?
int i;int j;for (i = 0; i i; j–) { cout << "+"; } cout << endl;}
A) A rectangle with six rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop.
B) A right triangle with six rows and seven columns of the plus sign. The number of columns increments by one on completion of one iteration of the inner loop.
C) A rectangle with seven rows and six columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop.
D) An inverted right triangle with six rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.
Ans: DTitle: What is output of nested for loops?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: MediumSection Ref: 4.8

51. What are the first and last values of i that get displayed by the following code snippet?
int n = 15;for (int i = 0; i <= n; i++){ for (int j = 0; j <= i; j++)
{ cout << i << endl; }
}
A) 0 and 14
B) 1 and 14
C) 0 and 15
D) 1 and 15
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: CTitle: What are first and last values displayed by nested for loop?Difficulty: MediumSection Ref: 4.8

52. In the following code snippet, when does the execution of the program switch from the inner loop to the outer loop?
int i;int j;for (i = 0; i <= 9; i++){ for (j = 1; j < 5; j++) { cout << "Hello" << endl; }}
A) When the inner loop is completed
B) When the program executes completely
C) When the condition for the outer loop is met
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) None of the listed items
Ans: ATitle: When does execution switch from inner to outer loop in snippet?
Difficulty: MediumSection Ref: 4.8

53. How many times will the cout statement execute in the following code snippet?
for (int num2 = 1; num2 <= 3; num2++){ for (int num1 = 0; num1 <= 2; num1++) { cout << num2 << " " << num1 << endl; }}
A) 3 times
B) 6 times
C) 9 times
D) The inner loop will not execute.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans. CTitle: How many times will the cout statement execute?Difficulty: MediumSection Ref: 4.8

54. How many times will the cout statement execute in the following code snippet?
for (int num2 = 0; num2 < 3; num2++){ for (int num1 = 0; num1 < 2; num1++) { cout << num2 << " " << num1 << endl; }}
A) 2 times
B) 3 times
C) 4 times
D) 6 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans. D
Title: How many times will the cout statement execute?Difficulty: MediumSection Ref: 4.8

55. Which of the following statements is correct about a sentinel?
A) A value that creates a bridge between a data set and unrelated input.
B) A value that indicates the end of an input sequence.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) A value that is part of the data to be processed by the program.
D) A value that terminates a program.

Ans: BTitle: Which statement about sentinels is correct?Difficulty: EasySection Ref: 4.5
56. Which of the following is not an actual input in a sequence of input values but is an indication of program termination?
A) String
B) Integer
C) Sentinel
D) Constant
Ans: CTitle: Which term describes input that signals program termination? Difficulty: EasySection Ref: 4.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
57. What is the sentinel value in the following code snippet?
int main(){ int age = 0; int sum_of_ages = 0; int stop = 1; cout <> age; while (age != -1) { sum_of_ages = sum_of_ages + age; cout <> age; } cout << "Sum of ages " << sum_of_ages; return 0;}
A) 0
B) 1
C) -1
D) There is no sentinel value.

Ans: CTitle: Which is the sentinel in this snippet?Difficulty: MediumSection Ref: 4.5

58. What will be the final output of the following code snippet when a user enters input values in the order 10, 20, 30, 40, 50, and -1?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main(){ double sum = 0; int count = 0; double salary = 0; double average = 0; cout << "Enter salaries (-1 to stop): " <> salary; if (salary != -1) { sum = sum + salary; count++; } } if (count > 0) { average = sum / count; cout << "The Average Salary: " << average << endl; } else { cout << "No data!" << endl; } return 0;}
A) The Average Salary: 0
B) The Average Salary: 30
C) The Average Salary: 24.83333
D) There will be no output as the code snippet will not compile.
Ans: BTitle: What is output of snippet with input that includes a sentinel?Difficulty: MediumSection Ref: 4.5
59. Which statement is correct about the execution of the loop in the following code fragment?
double num;int incr = 0;do{ incr = incr + 1; cout <> num;}while (num != 0);cout << incr << endl;
A) The loop executes only when 0 is entered.
B) The execution of the loop is independent of user input.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The program prints the count of positive inputs.
D) The loop executes at least once even if the user enters the sentinel value.
Ans. DTitle: Which statement is true about do loop with user input?Difficulty: HardSection Ref: 4.5
60. What will be the output of the following code snippet?
bool token = true;while (token){ cout << "Hello" << endl;}
A) “Hello” will be displayed infinite times.
B) No output because of compilation error.
C) No output after successful compilation.
D) “Hello” will be displayed only once.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What is output of while loop with Boolean condition?
Difficulty: EasySection ref: 4.5
61. What is the output of the following code snippet?
bool token = false;while (token){ cout << "Hello World!" << endl;}
A) No output
B) Hello World!
C) No output because of compilation error
D) Hello World! will be displayed infinitely many times
Ans: ATitle: What is output of while loop with Boolean condition?Difficulty: EasySection Ref: 4.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

62. What is the output of the following code snippet?
bool token = false;if (token){ cout << "Hello World!" << endl;}else{ cout << "Terminates" << endl;}
A) Terminates
B) Hello World!
C) No output because of compilation error
D) No output after successful compilation
Ans: ATitle: What is output of if/else with Boolean condition?Difficulty: EasySection Ref: 4.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
63. What will be the output of the following code snippet?
bool token1 = true;while (token1){ for (int i = 0; i < 10; i++) { cout << "Hello" << endl; } token1 = false;}
A) No output.
B) No output because of compilation error.
C) “Hello” will be displayed 10 times.
D) “Hello” will be displayed infinite times.

Ans: C
Title: What is output of while loop with Boolean condition?
Difficulty: MediumSection Ref: 4.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

64. What is the output of the following code snippet?
int i = 1;while (i <= 10){ cout << "Inside the while loop" << endl; i = i * 11;}
A) No output because of compilation error.
B) “Inside the while loop” will be displayed 10 times.
C) No output after successful compilation.
D) “Inside the while loop” will be displayed only once.
Ans: DTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

65. What is the outcome of the following code snippet?
bool val1 = true;bool val2 = false;while (val1){ if (val1) { cout << "Hello" << endl; } val1 = val2;}
A) No output will be displayed because of compilation error.
B) “Hello” will be displayed only once.
C) “Hello” will be displayed infinite times.
D) No output will be displayed even after successful compilation of the code snippet.
Ans. BTitle: What is output of while loop with nested if with Boolean conditions?Difficulty: MediumSection Ref: 4.5
66. Which of the following activities can be simulated using a computer?
A) Picking stocks
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Tossing a coin
C) Shuffling cards for a card game
D) All of the listed items
Ans: DTitle: Which activities can be computer simulated?Difficulty: EasySection Ref: 4.9
67. What will be the range of the random numbers generated by the following code snippet?
rand() % 100 + 1;
A) Between 1 and 99
B) Between 0 and 100
C) Between 0 and 99
D) Between 1 and 100
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: What range of random numbers will snippet produce?Difficulty: EasySection Ref: 4.9
68. What is the data type of the number generated by the rand function?
A) int
B) const
C) double
D) string
Ans: ATitle: What is data type generated by rand function?
Difficulty: EasySection Ref: 4.9

69. Which of the following code snippets will generate a random number between 0 and 99?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) srand (time(NULL));
val = rand() % 100;
B) srand (time(NULL));
val = rand() % 100 – 1;
C) srand (time(NULL));
val = rand() % 99;
D) srand (time(NULL));
val = rand() * 100;
Ans: ATitle: Which snippet will generate random number 0-99?Difficulty: EasySection Ref: 4.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
70. What is the output of the following code snippet, if it is run twice?
int main(){ int i; int num; for (i = 0; i < 10; i++) { num = rand(); cout << "Random Number: " << num << endl; } return 0;}
A) The code snippet will generate different sets of random numbers each time.
B) The code snippet will generate the same sets of random numbers each time.
C) There will be no output.
D) None of the listed items.
Ans: BTitle: What is output of snippet with rand when run twice?Difficulty: EasySection Ref: 4.9

71. Which of the following is the correct code snippet for throwing a pair of dice to get a sum of the numbers on two dice between 2 and 12 with different probabilities?
A) rand() % 11 + 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) rand() % 12 + 2
C) (rand() % 6 + 1) + (rand() % 6 + 1)
D) (rand() % 6) + (rand() % 6)

Ans: CTitle: Which code simulates throwing two dice and summing the result? Difficulty: HardSection Ref: 4.9

72. Which of the following is the correct code snippet for throwing a pair of 12-sided dice to get a sum of the numbers on two dice between 2 and 24 with different probabilities?
A) 2 * (rand() % 11 + 2)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) rand() % 23 + 2
C) (rand() % 12) + (rand() % 12)
D) (rand() % 12 + 1) + (rand() % 12 + 1)

Ans: DTitle: Which code simulates throwing two dice and summing the result? Difficulty: HardSection Ref: 4.9

73. How many times will the following loop run?
int i = 0;while (i < 5){ cout << i << endl; i++;}
A) 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 3
C) 4
D) 5
Ans: DTitle: How many times will while loop run?Difficulty: EasySection Ref: 4.1
74. What is the output of the code snippet given below?
int i = 0;while (i != 11){ cout << i << " "; i = i + 2;}
A) No output
B) 0 2 4 6 8
C) 10 12 14 16 18 …. (infinite loop)
D) 0 2 4 6 8 10 12 14 …. (infinite loop)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
75. How many times does the code snippet given below display “So far so good”?
int i = 0;while (i != 15){ cout << "So far so good" << endl; i++;}
A) Infinite times
B) 14 times
C) 15 times
D) 16 times
Ans: CTitle: How many times does while loop display result?Difficulty: MediumSection Ref: 4.1
76. What is the output of the code fragment given below?
int i = 0;int j = 0;while (i < 125){ i = i + 2; j++;}cout << j << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 0
B) 62
C) 63
D) 124
Ans: CTitle: What is output of while loop?Difficulty: MediumSection Ref: 4.1
77. What is the output of the following code snippet?
int i = 1;while (i < 20){ cout << i << " "; i = i + 2; if (i == 15) { i = 19; }}
A) 1 3 5 7 9 11 13 15 17 19
B) 1 3 5 7 9 11 13 19
C) 1 3 5 7 9 11 13 15 17
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 1 3 5 7 9 11 13 17 19
Ans: BTitle: What is output of while loop with nested if?Difficulty: MediumSection Ref: 4.1
78. What are the values of i and j obtained after the following code fragment is run?
int i = 40;int j = 30;int count = 0;while (count < 5){ i = i + i; i = i + 1; j = j – 1; j = j – j; count++;}cout << i<< endl << j;
A) i = 45, j = 1
B) i = 45, j = 35
C) i = 1311, j = 0
D) i = 1311, j = 35
Ans: CTitle: What are values of i and j after while loop?Difficulty: HardSection Ref: 4.1
79. How many times does the following code fragment display “Where is C?”?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i = 15;while (i >= 0){ cout << "Where is C?" << endl; i–;}
A) 14 times
B) 15 times
C) 16 times
D) Infinite times

Ans: CTitle: How many times does while loop display result?Difficulty: EasySection Ref: 4.1
80. What changes do you need to make in the following code snippet to display “Can you C?” exactly 5 times?
int i = 0;while (i <= 5){ cout << "Can you C?" << endl; i++;}
A) int i = 1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) while (i < 4)
C) while (i < 6)
D) No change required
Ans: ATitle: What changes need to while loop to display correct result?Difficulty: EasySection Ref: 4.1
81. What is the output of the following code fragment?
int i = 1;int sum = 0;while (i <= 13){ sum = sum + i; i = i + 3;}cout << "The value of sum is " << sum;
A) The value of sum is 0
B) The value of sum is 22
C) The value of sum is 35
D) The value of sum is 13
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: What is the output of while loop that sums?Difficulty: MediumSection Ref: 4.1
82. What is the output of the code snippet given below?
string s = “abcde”;int i = 1;while (i < 5){ cout << s.substr (i, 1); i++;}
A) No output
B) abcd
C) abcde
D) bcde
Ans: DTitle: What is the output of while loop with substr?Difficulty: MediumSection Ref: 4.1
83. How many times does the loop run in the following code fragment?
int i;for (i = 0; i < 60; i = i + 4){ cout << i << endl;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 1
B) 14
C) 15
D) 16

Ans: CTitle: How many times does for loop run?Difficulty: EasySection Ref: 4.3
84. How many times does the following loop execute?
double num;double sum = 0;for (int i = 0; i < 10; i++){ cout <> num; if (sum > num) { sum = num; } if (i == 5) { i = 9; }}
A) 0 times
B) 6 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 7 times
D) 8 times
Ans: BTitle: How many times does for loop with nested if execute?Difficulty: MediumSection Ref: 4.3
85. What is the output of the code snippet given below?
int i;int j = 0;for (i = 0; i < 6; i++){ if (i % 2 == 0) { i = i + 2; j++; } else { i++; j = j + 2; } j++;}cout << "i=" << i << ", j=" << j;
A) i = 7, j = 7
B) i = 7, j = 8
C) i = 8, j = 7
D) i = 8, j = 8
Ans: BTitle: What is the output of for loop with nested if/else?Difficulty: HardSection Ref: 4.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
86. How many times is the text “We may C” printed if the code snippet given below is run?
int i = 0;do{ cout << "We may C" << endl; i++; if (i % 4 == 0) { i = 11; }}while (i <= 10);
A) 4
B) 5
C) 10
D) 11
Ans: ATitle: How many times does do loop with nested if display result?Difficulty: MediumSection Ref: 4.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
87. How many times is the text “You had me at” printed if the code snippet given below is run?
int i = 0;do{ cout << "You had me at " << endl; if (i % 2 == 1) { i = 2; }}while (i != 0);
cout << "Hello!" << endl;
A) infinite loop
B) 1
C) 2
D) 3
Ans: BTitle: How many times does do loop with nested if display result?Difficulty: MediumSection Ref: 4.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

88. What is the output of the code snippet given below?
string s = “abcde”;int i = 1;do{ if (i > 1) { cout << s.substr (i, 1); }}while (i < 5);
A) No output
B) No output (Infinite loop)
C) abcde
D) bcde
Ans: BTitle: What is output of do loop with nested if?Difficulty: MediumSection Ref: 4.4
89. What is the output of the code snippet given below?
string s = “aeiou”;int i = 0;do{ i++; if (i >= 2) { i = 5; }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << s.substr (i, 1);}while (i < 5);
A) a
B) e
C) ae
D) aei
Ans: BTitle: What is output of do loop with nested if?Difficulty: MediumSection Ref: 4.4
90. How many times does the following loop run?
int i = 0;int j = 1;do{ cout << i << ";" << j <= 1);
A) 0 times
B) 2 times
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 3 times
D) 4 times
Ans: CTitle: How many times does do loop with nested if run?Difficulty: HardSection Ref: 4.4
91. What will be the output of the following code snippet?
int i;int j;for (i = 0; i i; j–) { cout << "+"; } cout << endl;}
A) A rectangle with seven rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop.
B) A right triangle with seven rows and seven columns of the plus sign. The number of columns increments by one on completion of one iteration of the inner loop.
C) A rectangle with seven rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop.
D) An inverted right triangle with seven rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.
Ans: DTitle: What is output of this nested for loop?Difficulty: MediumSection Ref: 4.8
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
92. What are the first and last values of i that get displayed by the following code snippet?
int n = 10;for (int i = 0; i <= n; i++){ for (int j = 0; j <= i; j++)
{ cout << i << endl;
}
}
A) 0 and 9
B) 1 and 9
C) 0 and 10
D) 1 and 10
Ans: CTitle: What are first and last values displayed by nested for loop?Difficulty: MediumSection Ref: 4.8
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

93. What are the first and last values of the loop variable counter that get displayed by the following code snippet?
int n = 10;for (int counter = 2; counter <= n; counter++){ for (int j = 0; j <= counter; j++) {
cout << counter << endl; }
}
A) 1 and 9
B) 2 and 10
C) 1 and 10
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 2 and 9
Ans: BTitle: What are first and last values displayed by nested for loop?Difficulty: MediumSection Ref: 4.8
94. How many times will cout statement execute in the following code snippet?
for (int num2 = 1; num2 <= 4; num2++){ for (int num1 = 0; num1 <= 3; num1++) { cout << num2 << " " << num1 << endl; }}
A) 4 times
B) 12 times
C) 16 times
D) The inner loop will not execute.
Ans. CTitle: How many times will the cout statement execute?Difficulty: MediumSection Ref: 4.8
95. What will be the final output of the following code snippet when a user enters input values in the order 10, 20, 30, 40, and –1?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main(){ double sum = 0; int count = 0; double salary = 0; double average = 0; cout << "Enter salaries (-1 to stop): " <> salary; if (salary != -1) { sum = sum + salary; count++; } } if (count > 0) { average = sum / count; cout << "The Average Salary: " << average << endl; } else { cout << "No data!" << endl; } return 0;}
A) The Average Salary: 0
B) The Average Salary: 25
C) The Average Salary: 20
D) The Average Salary: 15
Ans: BTitle: What is output of while/if/else snippet with input values that include a sentinel?Difficulty: MediumSection Ref: 4.5
96. What will be the output of the following code snippet?
bool token1 = true;while (token1){ for (int i = 0; i < 5; i++) { cout << "Hello there" << endl; } token1 = false;}
A) No output.
B) No output because of compilation error.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) “Hello there” will be displayed 5 times.
D) “Hello there” will be displayed infinite times.
Ans: CTitle: What is output of while with Boolean condition and nested for loop?Difficulty: MediumSection Ref: 4.5

97. What is the outcome of the following code snippet?
bool val1 = true;bool val2 = false;while (val1){ if (val1) { cout << "What do you C?" << endl; } val1 = val2;}
A) No output will be displayed because of compilation error.
B) “What do you C?” will be displayed only once.
C) “What do you C?” will be displayed infinite times.
D) No output will be displayed even after successful compilation of the code snippet.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans. BTitle: What is output of while loop with nested if when both have Boolean conditions?Difficulty: MediumSection Ref: 4.5

98. What will be the range of the random numbers generated by the following code snippet?
rand() % 50 + 1;
A) Between 1 and 49
B) Between 0 and 50
C) Between 0 and 49
D) Between 1 and 50
Ans: DTitle: What is range of random numbers generated by snippet?Difficulty: EasySection Ref: 4.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
99. What will be the range of the random numbers generated by the following code snippet?
rand() % 12 + 4;
A) Between 3 and 14
B) Between 4 and 15
C) Between 3 and 15
D) Between 4 and 16
Ans: BTitle: What is range of random numbers generated by snippet?Difficulty: EasySection Ref: 4.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
100. Which of the following code snippets will generate a random number between 0 and 79?
A) srand (time(NULL));
val = rand() % 80;
B) srand (time(NULL));
val = rand() % 80 – 1;
C) srand (time(NULL));
val = rand() % 79;
D) srand (time(NULL));
val = rand() * 80;Ans: ATitle: Which code generates random numbers 0-79?Difficulty: EasySection Ref: 4.9
1. Which process below helps with identifying the functions that make up a computer program?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Black boxes
B) Stepwise refinement
C) Parameter passing
D) Debugging
Ans: BTitle: Which process helps identify functions that make up a program?Difficulty: EasySection Ref: 5.7

2. The term “Black Box” is used with functions because
A) Only the implementation matters; the specification is not important.
B) Only the specification matters; the implementation is not important.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Only the arguments matter; the return value is not important.
D) Only the return value matters; the arguments are not important.
Ans: B
Title: Why is the term “black box” used with functions?
Difficulty: EasySection Ref: 5.1

3. One advantage of designing functions as black boxes is that
A) Many programmers can work on the same project without knowing the internal implementation details of functions
B) The result that is returned from black-box functions is always the same data type
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The implementation of the function is open for everyone to see
D) There are fewer parameters
Ans: A
Title: What is one advantage of designing functions as black boxes?
Difficulty: EasySection Ref: 5.1

4. What are the names (in order) of the parts of this function definition?
int my_fun (double a)
A) Return type, function name, parameter variable type, parameter variable name)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Return type, function name, parameter variable name, parameter variable type
C) Function name, function type, parameter variable type, parameter variable name
D) Function name, function type, parameter variable name, parameter variable type
Ans: A
Title: What are the parts of a function definition?
Difficulty: EasySection Ref: 5.2

5. Parameter variables should not be changed within the body of a function because
A) This will generate a compiler error
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) This will generate a run-time error
C) It is confusing because it mixes the concept of a parameter with that of a variable
D) It is confusing because parameter variables cannot store values
Ans: C
Title: Why shouldn’t parameter variables be changed within the body of a function?
Difficulty: EasySection Ref: 5.3

6. What is the output of the following code snippet?
int my_fun(int perfect)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
return ((perfect – 1) * (perfect – 1));
}
int main (){ for (int i = 0; i < 4; i++)
{
cout << my_fun(i) << " "; }
return 0;}
A) -1 0 1 4
B) 1 0 1 4
C) -1 0 1 4 9
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 1 4 9 16
Ans: B
Title: What is the output of the following code snippet?
Difficulty: MediumSection Ref: 5.3

7. Which option represents a legal invocation of the function square()?
string square(int a)
{
return (“Commencing”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) int a = square(4);
B) string a = square(“help”);
C) double a = square(4.0);
D) string a = square(4);
Ans: D
Title: Which option is a legal invocation of the given function?
Difficulty: EasySection Ref: 5.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
8. Which statement about the steps for implementing a function is true?
A) Pseudocode is the first step in the process for implementing a function
B) Pseudocode is the last step in the process for implementing a function
C) Unit testing (testing in isolation) of the implemented function is an important first step
D) Unit testing (testing in isolation) of the implemented function is an important final step
Ans: D
Title: Which statement about the steps for implementing a function is true?
Difficulty: EasySection Ref: 5.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

9. What is the problem with the code snippet below?
string val()
{
string result = “candy”;
return;
}
int main(){
cout << val() << endl; return 0;}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The function val does not have a return value.
B) The function val does not have any parameter variables.
C) The use of val in the cout statement of main is illegal.
D) The string data type cannot be returned from a function.
Ans: ATitle: What is the problem with the code snippet?
Difficulty: MediumSection Ref: 5.4

10. What is the problem with the code snippet below?
void cost(int price, int reps)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
for (int i = 0; i < reps; i++)
{
cout << price;
}
return;
}
int main(){
cout << cost(10, 4) << endl; return 0;}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The function cost is invoked with the wrong parameters
B) The function cost uses uninitialized variables
C) The function cost returns void and therefore cannot be used in a cout statement
D) The function cost must return an integer value
Ans: CTitle: What is the problem with the given code snippet?
Difficulty: MediumSection Ref: 5.5

11. If a function is declared to return “void”, then which statement below is true?
A) The function cannot return until reaching the end of the function body
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The function needs a return statement that always returns the integer value zero
C) The function needs a return statement with no return value
D) The function cannot be invoked unless it is in an assignment statement
Ans: C
Title: Which statement about functions that return “void” is true?
Difficulty: EasySection Ref: 5.5

12. The purpose of a function that returns “void” is
A) To satisfy compiler warnings
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) To package a repeated task as a function even though the task does not yield a value
C) To force a value to be returned in case the “return” statement is forgotten
D) To insert a temporary implementation of a function that can be refined later
Ans: B
Title: What is the purpose of functions without a return value?
Difficulty: EasySection Ref: 5.5

13. What is stepwise refinement?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The process of unit testing
B) The process of breaking complex problems down into smaller, manageable steps
C) The design of pseudocode for black-box functions
D) The use of a temporary implementation of a function that can be improved later
Ans: B
Title: What is stepwise refinement?
Difficulty: EasySection Ref: 5.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
14. Why is hand-tracing, or manually walking through the execution of a function, helpful?
A) It is an effective way to understand a function’s subtle aspects
B) It guarantees that the function will compile without errors
C) It makes unit testing unnecessary
D) It enforces the “black-box” concept of function design
Ans: A
Title: What is the purpose of a manual walk-through of a function?
Difficulty: EasySection Ref: 5.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
15. When hand-tracing functions, the values for the parameter variables
A) Are the same each time the function is invoked
B) Need not be traced since they are never returned
C) May be undetermined or missing when the function executes
D) Are determined by the arguments supplied in the code that invokes the function
Ans: D
Title: What is true about the values for parameter variables when hand-tracing functions?
Difficulty: EasySection Ref: 5.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

16. A stub function is
A) A short function
B) A function that has been unit tested
C) A function that acts as a placeholder and returns a simple value so another function can be tested
D) A function that is broken down into smaller steps through step-wise refinement
Ans: C
Title: What is a stub function?
Difficulty: EasySection Ref: 5.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

17. The variable name perfect in the function my_fun in the code snippet below is used as both a parameter variable and a variable in a nested block within the function. Which statement about this situation is true?
int my_fun(int perfect)
{
{
int perfect = 0;
return ((perfect – 1) * (perfect – 1));
}
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) This multiple declaration of the variable perfect will not compile
B) While this is legal, it is confusing and creates a situation known as shadowing
C) Since the scopes of these variables do not overlap, there is no problem
D) This situation rarely occurs and the compiler always issues a warning
Ans: B
Title: Which statement about variable declarations within functions is true?
Difficulty: MediumSection Ref: 5.8

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
18. What is the output from the following code snippet?
int my_fun(int perfect)
{
{
int perfect = 0;
return ((perfect – 1) * (perfect – 1));
}
return perfect;
}
int main(){ for (int i = 0; i < 4; i++)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << my_fun(i) << " "; }
return 0;}

A) -1 0 1 4
B) 1 0 1 4
C) 0 0 0 0
D) 1 1 1 1
Ans: D
Title: What is the output from the code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: HardSection Ref: 5.8

19. A function uses a reference parameter when
A) It is designed to update a variable supplied as an argument
B) The parameter will take on a number of different values
C) The argument supplied to the function is an expression
D) The function will not have a return value
Ans: ATitle: When does a function use a reference parameter?
Difficulty: MediumSection Ref: 5.9
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

20. What is the problem with the following code snippet?
double discount(double& cost)
{
return (0.9 * cost);
}
int main (){
cout << discount(49.95);}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The data type returned by the function discount does not match the return type
B) The argument to the function discount must be a variable
C) The function discount must return void
D) The code is correct
Ans: B
Title: What is the problem with the following code snippet?
Difficulty: HardSection Ref: 5.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

21. Which line of code in the snippet below is the recursive invocation of function my_fun?
1 int my_fun(int perfect)
2 {
3 return ((perfect – 1) * (perfect – 1));
4 }
5 int main()6 {7 cout << my_fun(my_fun(12));
8 return 0;9 }
A) 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 3
C) 7
D) There is no recursive invocation
Ans: D
Title: Which line of code is the recursive invocation?
Difficulty: MediumSection Ref: 5.10

22. Which of the following is NOT a good practice when developing a computer program?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Put as many statements as possible into the main function
B) Document the purpose of each function parameter
C) Decompose a program into many small functions
D) Place code that is used multiple times into a separate function
Ans: ATitle: Which is NOT a good practice in developing a computer program?Difficulty: EasySection Ref: 5.7
23. Which of the following statements about variables is true?
A) The same variable name can be used in two different functions.
B) The same variable name can be used for two different variables in a single function.
C) You should use global variables whenever possible.
D) A variable is visible from the point at which it is defined until the end of the program.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: Which statement about variables is true?Difficulty: EasySection Ref: 5.8
24. Which of the following is not legal in a function definition?
A) Parameter variable names
B) Parameter variable data types
C) One return value
D) Multiple return values
Ans: DTitle: Which is not legal in a function definition?Difficulty: EasySection Ref: 5.2
25. The ceil function in the C++ standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about ceil(12.6)?
A) The argument is 12.6, and the return value is 13.
B) The argument is 12.6, and the return value is 12.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The argument is 13, and the return value is 12.6.
D) The argument is 12, and the return value is 12.6.
Ans: ATitle: Which is true about ceil(12.6)?Difficulty: MediumSection Ref: 5.2
26. Which of the following is true about functions?
A) Functions can have only one parameter and can return only one return value.
B) Functions can have multiple parameters and can return multiple return values.
C) Function can have multiple parameters and can return one return value.
D) Functions can have one parameter and can return multiple return values.
Ans: CTitle: Which is true about functions?Difficulty: EasySection Ref: 5.1
27. Consider a function named calc, which accepts two numbers as integers and returns their sum as an integer. Which of the following is the correct statement to call the function calc?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) calc(2, 3.14);
B) int sum = calc(2, 3);
C) calc();
D) int sum = calc(“2”, “3”);
Ans: BTitle: Which is correct way call the function calc (with two int parameters)?Difficulty: MediumSection Ref: 5.2
28. What is the output of the following code snippet?
int pow(int base, int power){ int result = 1; for (int i = 0; i < power; i++) { result = result * base; } return result;}int main(){ cout << pow(pow(2, 2), 2) << endl; return 0;}
A) 4
B) 8
C) 16
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 32
Ans: CTitle: What is output of snippet (with function call as argument)?Difficulty: HardSection Ref: 5.2
29. Which of the following must be provided when defining a function?
A) A name for the function, a name for each parameter, and a name for the return value
B) A name for the function and a name for the return value
C) A name for the function but not for parameters or the return value
D) A name for the function, a name and type for each parameter, and a type for the return value
Ans: DTitle: Which must be provided when defining a function?Difficulty: EasySection Ref: 5.2
30. The statements that are executed when a function is called are known as:
A) The body of the function
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Parameters
C) The interface of the function
D) The return value of the function
Ans: ATitle: The statements executed when a function is called are known as:Difficulty: EasySection Ref: 5.2
31. In an accounting application, you discover several places where the total profit, a double value, is calculated. Which of the following should be done to improve the program design?
A) The next time the total profit is calculated, use copy and paste to avoid making coding errors.
B) Provide the same comment every time you repeat the total profit calculation.
C) Consider writing a function that returns the total profit as a double value.
D) All of the listed items.
Ans: CTitle: What should be done to improve (program that does same calculation repeatedly)?Difficulty: EasySection Ref: 5.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
32. Which of the following is the correct first line of a function definition named calc_average that accepts three int parameters and returns a double?
A) double calc_average()
B) calc_average(int a, int b, int c)
C) double calc_average(int a, int b, int c)
D) int calc_average(double a, double b, double c)
Ans: CTitle: Which is first line of function definition … three int parameters and returns a double?Difficulty: MediumSection Ref: 5.2
33. What is the error in the following function definition?
int doubler(int old_value){ double new_value = old_value * 2;}
A) The function does not return a value.
B) The function returns a value of type double.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The function attempts to modify its input parameter.
D) No error.
Ans: ATitle: What is the error in this function definition?Difficulty: MediumSection Ref: 5.2
34. What is the error in the following function definition?
int find_max(int first, second){ int max = 0; if (first > second)
{ max = first; }
else
{ max = second;
{ return max;}
A) The function returns the minimum instead of the maximum of the two parameters.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The function does not return a value.
C) The function returns 0 if the first and second parameters are equal.
D) The function does not specify a type for the second parameter.
Ans: DTitle: What is the error in this function definition?Difficulty: MediumSection Ref: 5.2
35. What is the syntax error in the following function definition?
string area(double r){ double a; a = 3.14 * r * r; return r * r;}
A) The function does not return the value a.
B) The function does not specify a return type.
C) The variable a is set but never used.
D) The value that is returned does not match the specified return type.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: What is the error in this function definition?Difficulty: HardSection Ref: 5.2
36. Which of the following is the correct definition of a function that calculates the area of a rectangle by multiplying its length by its width? The length and width parameters are double values and the function returns a double.
A) double area(double length, double width)
{ return length * width;
}
B) double area(double length, double width)
{ double area = length * width; return;
}
C) double area(double length, width)
{ return length * width;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
D) area(double length, double width)
{ return length * width;}
Ans: ATitle: Which correctly defines a function that calculates the area of a rectangle?Difficulty: HardSection Ref: 5.2
37. When should comments be written to describe functions?
A) When the functions are short
B) When the functions are long
C) When the functions are complicated
D) Whenever you write a function
Ans: DTitle: When should comments be written to describe functions?Difficulty: EasySection Ref: 5.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
38. Consider this function comment. Which of the following options is recommended in your textbook?
/** Computes the area of a rectangle. @param width the width of the rectangle @return the area of the rectangle*/double area(double width, double height){ double area = width * height; return area;}
A) The parameter “width” need not be described.
B) The first line of the comment should be omitted because it is obvious.
C) Both parameters should be described.
D) The @return clause of the comment should be omitted because it is obvious.
Ans: CTitle: Which is recommended in your textbook (for this function comment)?Difficulty: EasySection Ref: 5.2
39. What is created for each argument when a function is called?
A) return value
B) return variable
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) parameter variable
D) Nothing is created
Ans: CTitle: What is created for each argument when a function is called?Difficulty: EasySection Ref: 5.3
40. How are variables passed as input to a function?
A) By using the return statement
B) By using arguments
C) By using comments
D) By using the function name
Ans: BTitle: How are variables passed as input to a function?Difficulty: EasySection Ref: 5.3
41. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
void mystery(int in_value){ in_value = 2 * in_value;}int main(){ int years = 42; mystery(years); cout << years << endl; return 0;}
A) 42
B) 84
C) 0
D) 21
Ans: ATitle: What is output of snippet (that calls function from main)?Difficulty: MediumSection Ref: 5.3
42. Which of the following is the correct first line for a function definition that takes two arguments of type int and returns true if the first value is greater than the second value?
A) bool func(int a, int b)
B) boolean func(int a, int b)
C) int func(bool a, bool b)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) bool func(int a, b)
Ans: ATitle: Which is first line of function definition … two int arguments and returns true…?Difficulty: MediumSection Ref: 5.3
43. Suppose you need to write a function that calculates the area of a rectangle. Which of the following is the best choice for the declaration of this function?
A) void area(int a)
B) double area(double w, double h)
C) void area(double w, double h)
D) double area(double w)
Ans: BTitle: Which is best choice for declaring function that calculates area of rectangle?Difficulty: HardSection Ref: 5.3
44. Consider the function shown below.
int do_it(int x, int y){ int val = 0; if (x < y) { val = x + 1; } else { val = y – 1; }// the last statement goes here}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
What should be the last statement of this function?
A) An assignment statement
B) A return statement
C) An increment statement
D) A comparison statement
Ans: BTitle: What should be the last statement of this function?Difficulty: EasySection Ref: 5.4
45. What is the output of the following code snippet?
int absval(int a){ if (a < 0) { return -a; } else { return a; }}int main(){ cout << absval(-2); return 0;}
A) –2.0
B) –2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 2
D) 2.0
Ans: CTitle: What is output of snippet (that calls function from main)?Difficulty: MediumSection Ref: 5.4
46. Which of the following is true about function return statements?
A) A function can hold multiple return statements, but only one return statement executes in one function call.
B) A function can hold only one return statement.
C) A function can hold multiple return statements, and multiple return statements can execute in one function call.
D) A function can have maximum of two return statements.
Ans: ATitle: Which is true about function return statements?Difficulty: MediumSection Ref: 5.4
47. A programmer notices that the following code snippet uses the same algorithm for computing cost after taxes, but with different variables, in the two places as shown below, and in several other places in the program. What could be done to improve the program?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
const double TAX_RATE1 = 10;const double TAX_RATE2 = 5.5;double subtotal = price * (1 + TAX_RATE1) / 100;double total = subtotal + shipping * (1 + TAX_RATE2) / 100;
A) Declare the tax rates as variables, not constants.
B) Define a function that looks up tax rates for goods and shipping charges.
C) Define a function that prompts the user for an amount and a tax rate, then returns the total amount including the tax.
D) Define a function that computes the cost after taxes from the cost before taxes and the tax rate.
Ans: DTitle: What could be done to improve (program that does same calculation with different values)?Difficulty: EasySection Ref: 5.4
48. What step should you take after implementing a function?
A) Write the pseudocode.
B) Determine the parameters.
C) Test the function in isolation.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Define the scope of the function.
Ans: CTitle: What step should you take after implementing a function?Difficulty: EasySection Ref: 5.4
49. What is the problem with the definition of the following function that calculates and returns the tax due on a purchase amount?
double tax_due(double amount, double tax_rate){ double tax_due = 0.0; tax_due = amount * tax_rate;}
A) The tax_due function does not compile.
B) The data type of the input parameters is incorrect.
C) The tax_due calculation is incorrect.
D) The tax_due function does not return a value.
Ans: DTitle: What is problem with function?Difficulty: MediumSection Ref: 5.4
50. You need to write a function that calculates the shipping cost for an appliance, which depends on the item’s dimensions and weight. What should be the inputs and their data types for this function?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) double size, double weight
B) double size, double weight, double price
C) double size, double weight, double shipping_cost
D) double width, double height, double depth, double weight
Ans: DTitle: What should inputs and data types be for this function that …?Difficulty: MediumSection Ref: 5.4
51. Which of the following is the best choice for a return type from a function that prompts users to enter their password?
A) char
B) int
C) string
D) void
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: Which is best return type for function that prompts for password?Difficulty: EasySection Ref: 5.4
52. What is incorrect in the following code snippet?
void display_box(string str){ cout << "——–" << endl; cout << str << endl; cout << "——–" << endl;}int main(){ cout << display_box("Hello World"); return 0;}
A) display_box is called with incorrect parameters.
B) display_box should be called in an assignment statement.
C) The return value from display_box is never used.
D) display_box does not return a value; therefore, it cannot be used with cout <<.
Ans: DTitle: What is incorrect in snippet (that sends function result to cout)?Difficulty: Medium Section Ref: 5.5
53. Which of the following code snippets can be used for defining a function that does not return a value? The function should accept a string and then display the string followed by “And that’s all folks!” on a separate line.
A) string display_message(string str)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{ cout << str << endl; cout << "And that's all folks!" << endl;
}
B) void display_message(string str)
{ cout << str << endl; cout << "And that's all folks!" << endl;
}
C) void display_message(string str)
{ cout << str << endl; cout << "And that's all folks!" << endl; return str;
}
D) void display_message()
{ cout << str << endl; cout << "And that's all folks!" << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
Ans: BTitle: Which snippet can be used to define function that does not return a value?Difficulty: HardSection Ref: 5.5

54. Which of the following options describes the process of stepwise refinement?
A) Using parameters to pass information to a function
B) Using unit tests to test the behavior of functions
C) Decomposing complex tasks into simpler ones
D) All of the listed items
Ans: CTitle: Which describes the process of stepwise refinement?Difficulty: EasySection Ref: 5.7
55. What is the purpose of writing a stub function?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) To test another function without writing all the implementation details of the function that the function being tested calls
B) To provide a simpler implementation of a complex function
C) To run a unit test for another function
D) To call a function that is being developed
Ans: ATitle: What is the purpose of writing a stub function?Difficulty: MediumSection Ref: 5.7

56. What is the advantage of using pseudocode before actually writing C++ code?
A) Pseudocode is more precise than a verbal description of the problem solution.
B) Pseudocode shows how to break a large problem into several smaller ones.
C) Pseudocode is shorter than the C++ code would be.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) All of the listed items.
Ans: DTitle: What is advantage of using pseudocode before writing code?Difficulty: MediumSection Ref: 5.7
57. For a program that reads three letter grades and calculates an average of those grades, which of the following would be a good design based on stepwise refinement?
A) Write one function that reads three letter grades, converts each letter grade to a number, and calculates the average of the three numbers.
B) Write one function that reads three letter grades, and a second function to convert each letter to a number and calculate the average of the three numbers.
C) Write one function that reads a letter grade and returns the number equivalent, and one function that computes the average of three numbers.
D) None of the above, stepwise refinement cannot be applied to this problem.
Ans: CTitle: For a program that… which would be good design using stepwise refinement?Difficulty: HardSection Ref: 5.7
58. An effective technique for understanding the subtle aspects of a function is to:
A) Perform hand-tracing of the function.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Write stub functions.
C) Use the C++ compiler to catch compile-time errors.
D) Write large functions to eliminate the run-time overhead of calling functions.
Ans: ATitle: An effective technique for understanding subtle aspects of a function is to:Difficulty: HardSection Ref: 5.7
59. In the following code snippet, what is the scope of variable b?
void func1(){ int i = 0; double b = 0;}void func2(){}int main(){ func1(); func2(); return 0;}
A) It can be used only in func1().
B) It can be used in user-defined functions, func1() and func2().
C) It can be used anywhere in this program.
D) It can be used in many programs.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: ATitle: In this snippet, what is the scope of variable b?Difficulty: MediumSection Ref: 5.8

60. Which option represents the output of the following code snippet?
int assign_priority(int priority){ return priority + 2;}int main(){ int priority = assign_priority(3); cout << "Priority: " << priority << endl; return 0;}
A) Priority: 2
B) Priority: 3
C) Priority: 5
D) There is no output because the program does not compile

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: What is output of snippet (with duplicate variable names)?Difficulty: HardSection Ref: 5.8
61. Which of the following is correct about a global variable?
A) It is declared before all the functions in a program.
B) It is visible to all the functions declared after it.
C) It is declared in the main function.
D) It is declared within the scope of a function.

Ans: BTitle: Which is correct about a global variable?Difficulty: EasySection Ref: 5.8

62. On executing the following code snippet, what is the value of the global variable gvar?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int gvar = 1;int main(){ int gvar = 0; gvar = gvar + 10; cout << gvar; return 0;}
A) 1
B) 10
C) 11
D) 0

Ans: ATitle: What is value of global variable (when main has variable of same name)?Difficulty: MediumSection Ref: 5.8
63. For the given code snippet, which of the following statements is true?
double raise(double rate){ double new_pay_rate = rate * 1.1; return new_pay_rate;}int main(){ double rate = 40.0; double new_pay_rate = 0.0; new_pay_rate = raise(rate); cout << "Pay rate: " << new_pay_rate << endl; return 0;}
A) The code snippet executes and displays “Pay rate: 40.0”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The code snippet executes and displays “Pay rate: 44.0”
C) The code snippet executes and displays “Pay rate: 0.0”
D) There is no output because the program does not compile

Ans: BTitle: Which is true (about snippet with duplicate variable names)?Difficulty: HardSection Ref: 5.8
64. What must a reference parameter refer to in a function call?
A) A variable
B) An expression
C) A return statement
D) A constant
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: What must a reference parameter refer to in a function call?Difficulty: EasySection Ref: 5.9
65. Which of the following function declarations would be appropriate for a function that updates the largest parameter, if the value of the current parameter is greater than largest?
The function body is shown here:
if (largest < current) { largest = current; }
A) void update_largest(int& largest, int current)
B) void update_largest(int largest, int current)
C) void update_largest(int largest, int& current)
D) void update_largest(int& largest, int& current)

Ans: ATitle: Which declaration is best for function that updates the largest parameter…?Difficulty: MediumSection Ref: 5.9
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
66. What are the values of x and y after executing the given code snippet?
void mystery(int& a, int& b){ a = b; b = a;}int main(){ int x = 10; int y = 11; mystery(x, y); return 0;}
A) x = 10 and y = 11
B) x = 11 and y = 10
C) x = 0 and y = 0
D) x = 11 and y = 11

Ans: DTitle: What are values of x and y after snippet (with reference parameters)?Difficulty: MediumSection Ref: 5.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
67. Which of the following options represents the output of the given code snippet?
#include void prevnext(int a, int& prv, int& nxt){ prv = a – 1; nxt = a + 1;}int main(){ int a = 100; int b = 0; int c = 0; prevnext(a, b, c); cout << "Previous = " << b << ", Next = " << c; return 0;}
A) Previous = 100, Next = 101
B) Previous = 99, Next = 100
C) Previous = 99, Next = 101
D) Previous = 101, Next = 100

Ans: CTitle: What is output of snippet (with reference parameters)?Difficulty: HardSection Ref: 5.9
68. What is the output of the following code snippet?
void prevnext(int a, int& prv, int nxt){ prv = a – 1; nxt = a + 1;}int main(){ int a = 100; int b = 0; int c = 0; prevnext(a, b, c); cout << "Previous = " << b << ", Next = " << c; return 0;}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Previous = 100, Next = 101
B) Previous = 99, Next = 101
C) Previous = 99, Next = 0
D) Previous = 0, Next = 101
Ans: CTitle: What is output of snippet (with reference parameters)?Difficulty: HardSection Ref: 5.9
69. What is the output of the following code snippet?
int black_box(int a){ int val; if (a <= 0) { val = 1; } else { val = a + black_box(a – 2); } return val;}int main(){ cout << black_box(4); return 0;}
A) 4
B) 1
C) 7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 2
Ans: CTitle: What is output of snippet (with recursive function)?Difficulty: EasySection Ref: 5.10
70. What is the output of the following code snippet?
#include
int fun(int x){ int ret_value = 0; if (x > 5) { ret_value = x; } else { ret_value = fun(2 * x); } return ret_value;}int main(){ cout << "fun(2) = " << fun(2); return 0;}
A) fun(2) = 4
B) fun(2) = 8
C) fun(2) = 16
D) fun(2) = 32

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: BTitle: What is output of snippet (with recursive function)?
Difficulty: MediumSection Ref: 5.10

71. Based on the code snippet, which of the following statements is correct?
#include void reoccur(int count){ cout << count << endl; reoccur(count + 1);}
int main()
{ reoccur(1); return 0;}
A) The code snippet gives a compilation error as the reoccur function cannot call itself.
B) The code snippet executes and gets into an infinite loop, displaying 1, 2, 3, 4, and so on.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The code snippet executes and displays 1.
D) The code snippet executes and does not produce any output.
Ans: BTitle: What is true about snippet (with recursive function)?Difficulty: EasySection Ref: 5.10

72. What is the output if the function call is testmyval(6) in the following code snippet?
void testmyval(int nval){ if (nval > 0) { testmyval(nval – 2); } cout << nval << " ";}
A) 0 2 4 6
B) 0 0 0 0
C) 6 6 6 6
D) 6 4 2 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: What is output of this call to (recursive function)?Difficulty: MediumSection Ref: 5.10

73. What is the output if the function call is div(10) in the following code snippet?
void div(int n){ if (n > 2) { div(n % 3); } cout << n / 3 << " ";}
A) 0 10
B) 3
C) 0 3
D) 10
Ans: CTitle: What is output of this call to (recursive function)?Difficulty: EasySection Ref: 5.10

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
74. Which of the following code snippets calculates the factorial of a given number? (Hint: Factorial of 5 = 5! = 1 * 2 * 3 * 4 * 5 = 120)
A) int factorial(int num)
{ return num * factorial(num – 1);}
B) int factorial(int num)
{ if (num == 1) { return 1; } return num * factorial(num);}
C) int factorial(int num)
{ if (num == 1) { return 1; } cout << num * factorial(num – 1);}
D) int factorial(int num)
{ if (num == 1) { return 1; } return num * factorial(num – 1);}
Ans: DTitle: Which snippet calculates the factorial of a given number?Difficulty: MediumSection Ref: 5.10
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

75. What is the output if the function call is recstr(“#”, 5) in the following code snippet?
void recstr(string s, int d){ if (d <= 1) { cout << d; } else { s = s + "/"; recstr(s, d – 2); cout << s << d; }}
A) 1//#3/#5
B) 1#//3#/5
C) 1##/#/5
D) 0##/#/5
Ans: BTitle: What is output of this call to (recursive function)?Difficulty: HardSection Ref: 5.10

76. The ceil function in the C++ standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about ceil(56.75)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The argument is 56.75, and the return value is 57.
B) The argument is 56.75, and the return value is 56.
C) The argument is 57, and the return value is 56.75.
D) The argument is 56, and the return value is 56.75.
Ans: ATitle: Which is true about ceil(56.75)?Difficulty: MediumSection Ref: 5.2

77. Consider a function named avg, which accepts four numbers as integers and returns their average as a double. Which of the following is the correct statement to call the function avg?
A) avg(2, 3.14, 3, 5);
B) double average = avg(2, 3, 4, 5);
C) avg();
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) double average = avg(“2”, “3”, “4”, “5”);
Ans: BTitle: Which is correct way call the function avg (with four int parameters)?Difficulty: MediumSection Ref: 5.2

78. What is the output of the following code snippet?
int recurr_average(int num){ int sum = 0; for (int x = 1; x <= num; x++) { sum = sum + x; }
return sum / num;
}int main{ cout << recurr_average(recurr_average(16)) << endl; return 0;}
A) 4
B) 8
C) 12
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 16
Ans: ATitle: What is output of snippet (with function call as argument)?Difficulty: HardSection Ref: 5.2

79. In a vehicle mileage application, you enter number of miles traveled by a vehicle and the amount of gasoline used for 30 consecutive days. From this data the average monthly mileage of the vehicle is calculated. Which of the following should be done to improve the program design?
I. The next time the average monthly mileage is calculated, use copy and paste to avoid making coding errors.
II. Provide the same comment every time you repeat the average monthly mileage calculation
III. Consider writing a function that returns the average monthly mileage as a double value

A) I
B) II
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) III
D) I, II, III
Ans: CTitle: What should be done to improve (program that does same calculation repeatedly)?Difficulty: EasySection Ref: 5.6

80. Which of the following is the correct first line of a function definition named calc_sum that accepts four int parameters and returns a double?
A) double calc_sum()
B) calc_sum(int a, int b, int c, int d)
C) double calc_sum(int a, int b, int c, int d)
D) int calc_sum(double a, double b, double c, double d)
Ans: CTitle: Which is first line of function definition … four int parameters and returns a double?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: MediumSection Ref: 5.3

81. What is the error in the following function definition?
int tripler(int num_para){ double result = num_para * 3;}
A) The function does not return a value.
B) The function returns a value of type double.
C) The function does not modify its input parameter.
D) None of the listed items.
Ans: ATitle: What is the error in this function definition?Difficulty: MediumSection Ref: 5.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

82. What is the error in the following function definition?
int find_min(int x, y){ int min = 0; if (x < y) { min = x; } else { min = y; } return min;}
A) The function returns the maximum instead of the minimum of the two arguments.
B) The function does not return a value.
C) The function returns 0 if the first and second arguments are equal.
D) The function does not specify a type for the second parameter variable.
Ans: DTitle: What is the error in this function definition?Difficulty: MediumSection Ref: 5.3

83. What is the syntax error in the following function definition?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
string parameter(double r){ double result; result = 2 * 3.14 * r; return result;}
A) The function does not return the value result.
B) The function does not specify result return type.
C) The variable result is set but never used.
D) The value that is returned does not match the specified return type.
Ans: DTitle: What is the error in this function definition?Difficulty: HardSection Ref: 5.3

84. Consider this function comment. Which of the following options is recommended in your textbook?
/** Computes the area of a cuboid. @param width the width of the cuboid @return the area of the cuboid*/double area(double width, double height, double length){ double result = width * height * length; return result;}
A) The parameter “width” need not be described.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The first line of the comment should be omitted because it is obvious.
C) All of the parameters should be described.
D) The @return clause of the comment should be omitted because it is obvious.
Ans: CTitle: Which is recommended in your textbook (for this function comment)?Difficulty: EasySection Ref: 5.3

85. What is the output of the following code snippet?
void double_amount(int in_value){ in_value = 2 * in_value;}int main(){ int principal_amt = 2000; double_amount(principal_amt); cout << principal_amt << endl; return 0;}
A) 2000
B) 4000
C) 1000
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 0
Ans: ATitle: What is output of snippet (that calls function from main)?Difficulty: MediumSection Ref: 5.4

86. Which of the following is the correct first line for a greater_than function definition that takes two arguments of type double and returns true if the first value is greater than the second value?
A) bool greater_than(double a, double b)
B) boolean greater_than(double a, double b)
C) double greater_than(bool a, bool b)
D) bool greater_than(double a, b)
Ans: ATitle: Which is first line of function definition … two double parameters and returns true…?Difficulty: MediumSection Ref: 5.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
87. Suppose you need to write a function that calculates the volume of rectangular boxes. Which of the following is the best choice for the declaration of this function?
A) void volume(int a)
B) double volume(double w, double h, double l)
C) void volume(double w, double h, double l)
D) double volume(double w)
Ans: BTitle: Which is best choice for declaring function that calculates volume of rectangular box?Difficulty: HardSection Ref: 5.4

88. A programmer notices that the following code snippet uses the same algorithm for computing bank balances after interest, but with different variables, in the two places shown below and in several other places in the program. What could be done to improve the program?
const double RATE1 = 10;const double RATE2 = 5.5;double interest = investment * RATE1 / 100;…balance = balance + balance * RATE2 / 100;
A) Declare the rates as variables, not constants.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Define a function that looks up interest rates.
C) Define a function that prompts the user for an amount and a rate of interest, then returns the interest earned.
D) Define a function that computes the interest earned from an amount and a rate of interest.
Ans: DTitle: What could be done to improve (program that does same calculation with different values)?Difficulty: EasySection Ref: 5.6

89. You need to write a function that calculates the volume for a shape, which depends on the shape’s length, width, and height. What should be the inputs and their data types for this function?
A) double length, double height
B) double length
C) double length, double height, string depth
D) double width, double length, double height
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: What should inputs and data types be for this function that …?Difficulty: MediumSection Ref: 5.3

90. Which of the following is the best choice for a return type from a function that prompts users to enter their credit card number?
A) bool
B) int
C) string
D) short
Ans: CTitle: Which is best return type for function that prompts for credit card number?Difficulty: EasySection Ref: 5.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
91. What is incorrect in the following code snippet?
void text_in_rectangle(string str){ cout << "——–" << endl; cout << "|" << str << "|" << endl; cout << "——–" << endl;
}int main(){ cout << text_in_rectangle("Some Text"); return 0;}
A) text_in_rectangle is called with incorrect arguments.
B) text_in_rectangle should be called in an assignment statement.
C) The return value from text_in_rectangle is never used.
D) text_in_rectangle does not return a value; therefore, it cannot be used with cout <<.
Ans: DTitle: What is incorrect in snippet (that sends function result to cout)?Difficulty: MediumSection Ref: 5.5

92. Which of the following code snippets can be used for defining a function that does not return a value? The function should accept a string and then display the string followed by “Just Let Us C!” on a separate line.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) string show_string(string some_string)
{ cout << some_string << endl; cout << "Just Let Us C!" << endl;
}
B) void show_string(string some_string)
{ cout << some_string << endl; cout << "Just Let Us C!" << endl;
}
C) void show_string(string some_string)
{ cout << some_string << endl; cout << "Just Let Us C!" << endl; return some_string;
}
D) void show_string()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{ cout << some_string << endl; cout << "Just Let Us C!" << endl;
}
Ans: BTitle: Which snippet can be used to define function that does not return a value?Difficulty: HardSection Ref: 5.5

93. For a program that reads city names repeatedly from the user and calculates the distance from Head Office, which of the following would be a good design based on stepwise refinement?
A) Write one function that calculates distance randomly.
B) Write one function that reads city name.
C) Write one function that reads city name and calculates distance.
D) Stepwise refinement cannot be applied to this problem.
Ans: CTitle: For a program that… which would be good design using stepwise refinement?Difficulty: HardSection Ref: 5.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

94. Which of the following function declarations would be appropriate for a function that updates the smallest parameter, if the value of parameter is greater than smallest?
The function body is shown here:
if (smallest < parameter) { smallest = parameter; }
A) void update_smallest(int& smallest, int parameter)
B) void update_smallest(int smallest, int parameter)
C) void update_smallest(int smallest, int& parameter)
D) void update_smallest(int& smallest, int& parameter)

Ans: ATitle: Which declaration is best for function that updates the smallest parameter…?Difficulty: MediumSection Ref: 5.9
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

95. What are the values of num1 and num2 after executing the given code snippet?
void mystery(int& first_num, int& second_num){ first_num = second_num; second_num = first_num;}int main(){ int num1 = 10; int num2 = 11; mystery(num1, num2); return 0;}
A) num1 = 10 and num2 = 11
B) num1 = 11 and num2 = 10
C) num1 = 0 and num2 = 0
D) num1 = 11 and num2 = 11

Ans: DTitle: What are values of num1 and num2 after snippet (with reference parameters)?Difficulty: MediumSection Ref: 5.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

96. Which of the following options represents the output of the given code snippet?
#include void addsub(int a, int& sub, int& add){ sub = a – 1; add = a + 1;}int main(){ int a = 5; int b = 0; int c = 0; addsub(a, b, c); cout << "Subtract = " << b << ", Add = " << c; return 0;}
A) Subtract = 6, Add = 6
B) Subtract = 4, Add = 5
C) Subtract = 4, Add = 6
D) Subtract = 5, Add = 5

Ans: CTitle: What is output of snippet (with reference parameters)?Difficulty: HardSection Ref: 5.9

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
97. Which of the following options represents the output of the given code snippet?
#include void addsub(int a, int& sub, int add){ sub = a – 1; add = a + 1;}int main(){ int a = 5; int b = 0; int c = 0; addsub(a, b, c); cout << "Subtract = " << b << ", Add = " << c; return 0;}
A) Subtract = 6, Add = 6
B) Subtract = 4, Add = 5
C) Subtract = 4, Add = 0
D) Subtract = 0, Add = 5

Ans: CTitle: What is output of snippet (with reference parameters)?Difficulty: HardSection Ref: 5.9

98. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
int some_func(int x){ int result = 0; if (x > 10) { result = x; } else { result = some_func(4 * x); } return result;}int main(){ cout << "some_func(2) = " << some_func(2); return 0;}
A) some_func(2) = 8
B) some_func(2) = 16
C) some_func(2) = 32
D) some_func(2) = 64

Ans: CTitle: What is output of snippet (with recursive function)?
Difficulty: MediumSection Ref: 5.10

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

99. Based on the code snippet, which of the following statements is correct?
#include void recursive_func(int count){ recursive_func(count + 2); cout << count << endl;}
int main()
{ recursive_func(1); return 0;}
A) The code snippet gives a compilation error because the recursive_func function cannot call itself.
B) The code snippet executes and gets into an infinite loop but does not print anything.
C) The code snippet executes and displays 1.
D) The code snippet executes and does not produce any output.
Ans: BTitle: What is true about snippet (with recursive function)?Difficulty: EasySection Ref: 5.10
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

100. What is the output if the function call is hashdate(“#”, 6) in the following code snippet?
void hashdate(string s, int d){ if (d <= 1) { cout << d; } else { s = s + "/"; hashdate(s, d – 2); cout << s << d; }}
A) 0#///2#//4#/6
B) 0#/2#//4#///6
C) 0/2#//4#///6#
D) 0///2#//4#/6#
Ans: ATitle: What is output of this call to (recursive function)?Difficulty: HardSection Ref: 5.10

1. Consider the following line of code:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int myarray[15];Which one of the following options is a valid line of code for displaying the eighth element of myarray?
A) cout << myarray[8];
B) cout << myarray(8);
C) cout << myarray(7);
D) cout << myarray[7];
Ans: DTitle: Which code displays the eighth element of myarray?Difficulty: EasySection Ref: 6.1
2. Identify the correct statement for defining an integer array named numcount of five elements.
A) int numcount[4];
B) int numcount[5];
C) int numcount[];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) int [5]numcount;

Ans: BTitle: Which statement defines integer array numcount with five elements?Difficulty: EasySection Ref: 6.1
3. Which one of the following statements is an invalid initialization of an array named myarray?
A) int myarray[ ] = { 0, 1, 2, 3, 4 };
B) int myarray[5] = { 0, 1, 2, 3, 4, 5 };
C) int myarray[5] = { 0, 1, 2, 3 };
D) int myarray[4] = { 0, 1, 2, 3 };
Ans: BTitle: Which array initialization statement is invalid?Difficulty: MediumSection Ref: 6.1
4. Consider the following code snippet:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int numarray[ ] = { 1, 2, 3, 4, 5 };cout << numarray[1];cout << numarray[4];What is the output of the code snippet?
A) 15
B) 14
C) 25
D) 04
Ans: CTitle: What are values of the elements at the given array indexes?Difficulty: MediumSection Ref: 6.1
5. Consider the following code snippet:
int ctr = 0;int myarray[3]; for (int i = 0; i < 3; i++){ myarray[i] = ctr; ctr = ctr + i;}cout << myarray[2];What is the output of the code snippet?
A) 0
B) 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 2
D) 3

Ans: BTitle: What is the value at the given array index after for loop executes?Difficulty: HardSection Ref: 6.1
6. Consider the following code snippet:
int arrmarks[5];for (int cnt = 0; cnt < 5; cnt++){ cout <> arrmarks[cnt];}Assume that a user enters 35, 56, 78, 90, and 45 as marks. What is stored in the element with the index number 3?
A) 45
B) 78
C) 90
D) 56
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: What is value at given array index after for loop executes?Difficulty: MediumSection Ref: 6.1

7. Consider the following code snippet:
int marks[5] = { 35, 68, 90, 45, 67 };for (int n = 0; n <= 5; n++){ cout << marks[n] << endl;}What is the result of executing this code snippet?
A) The code snippet does not give any output.
B) The code snippet displays all the marks stored in the array without any redundancy.
C) The code snippet has a bounds error.
D) The code snippet executes an infinite loop.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: CTitle: What is result of for loop that traverses array?Difficulty: MediumSection Ref: 6.1

8. Consider the following code snippet:
int arrmarks[5];int total;for (int cnt = 1; cnt <= 5; cnt++){ cout <> arrmarks[cnt]; total = total + arrmarks[cnt];}cout << total;Which one of the following outputs is displayed on executing the given code snippet?
A) The code snippet displays the total marks of all five subjects.
B) The code snippet gives a runtime time error, not an output.
C) The code snippet has a bounds error or displays redundant data.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The code snippet displays zero.
Ans: CTitle: Which is result of for loop that fills an array and totals its elements?Difficulty: HardSection Ref: 6.1

9. Which one of the following statements is valid for vectors?
A) The size of a vector is fixed.
B) The size of a vector should be specified at the time of its definition.
C) Vectors include values randomly.
D) Vectors are empty by default.

Ans: DTitle: Which statement is true about vectors?Difficulty: EasySection Ref: 6.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

10. Which one of the following options can be used to store a set of values when the size of the set is not known at the time of compilation?
A) Vectors
B) Arrays
C) Variables
D) Functions
Ans: ATitle: Which can be used to store a set of values whose size is unknown at compilation?Difficulty: EasySection Ref: 6.7
11. What is the result of the following definition of a vector?
vector chkdata;
A) The statement causes a compile time error as the size of the vector is not defined.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The statement creates a vector of size 0.
C) The statement creates a vector with unlimited size.
D) The statement creates a vector of size 1.
Ans: BTitle: What is the result of this definition of a vector?Difficulty: MediumSection Ref: 6.7
12. Consider the following code snippet:
vector vectdata;vectdata.push_back(90);What is the size of the vector vectdata after the given code snippet is executed?
A) 0
B) 1
C) 90
D) 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: BTitle: What is the size of the given vector after push_back(90)?Difficulty: EasySection Ref: 6.7
13. Consider the following code snippet:
vector num(3);num[0] = 1;num[1] = 2;num[2] = 3;num.pop_back();Which element or elements of the vector are removed by the pop_back() function in the given code snippet?
A) The element with index 0
B) The element with index 1
C) The element with index 2
D) All the elements
Ans: CTitle: Which vector elements are removed by pop_back() in this snippet?Difficulty: MediumSection Ref: 6.7
14. What is the valid range of index values for an array of size 7?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 0 to 7
B) 1 to 6
C) 1 to 7
D) 0 to 6

Ans: DTitle: What is the range of index values for an array of size 7?Difficulty: EasySection Ref: 6.1
15. Consider the following code snippet:
int numarray[6];for (int cnt = 1; cnt < 6; cnt++){ numarray[cnt] = cnt + 1;}Which one of the following statements is correct about the given code snippet?
A) The for loop initializes all the elements of the array.
B) The for loop initializes all the elements except the first element.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The for loop initializes all the elements except the last element.
D) The for loop initializes all the elements except the first and last elements.

Ans: BTitle: Which statement is true about this for loop that initializes an array?Difficulty: HardSection Ref: 6.1
16. Consider the following code snippet:
int num[3];for (int cnt = 1; cnt < 3; cnt = cnt++){ num[cnt] = cnt + 1; cout << num[cnt];}What is the output of the given code snippet?
A) 23
B) 12
C) 13
D) 11
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: What is output of this for loop that traverses/displays array elements?Difficulty: MediumSection Ref: 6.1
17. What is the value stored in the last element of an array named numdata with the given definition?
int numdata[3] = { 1, 2 };
A) The last element stores value 1.
B) The last element stores value 2.
C) The last element stores value 0.
D) The answer cannot be determined from the information given.
Ans: CTitle: What is value stored in last element of array defined here?Difficulty: EasySection Ref: 6.1
18. Consider the following code snippet:
int number[5]; // Line 1number[5] = 5 // Line 2Which one of the following statements is correct for the given code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Line 2 declares and initializes an array of five elements with value 5.
B) Line 2 causes a bounds error because 5 is an invalid index number.
C) Line 2 initializes the fifth element of the array with value 5.
D) Line 2 initializes all the elements of the array with value 5.
Ans: BTitle: Which statement is true for snippet with array bounds error?Difficulty: EasySection Ref: 6.1
19. What is the output of the following code snippet?
vector num(3);num.push_back(3);cout << num.size();
A) 1
B) 2
C) 3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 4
Ans: DTitle: What is value of vector.size after this snippet with push_back?Difficulty: EasySection Ref: 6.7
20. Your program needs to store a sequence of integers of unknown length. Which of the following can you use?
A) An array declared as int a[];
B) A vector declared as vector a;
C) An array declared as int a[1000]; with a companion variable.
D) All of the listed items.
Ans: BTitle: Which can you use to store a sequence of integers of unknown length?Difficulty: EasySection Ref: 6.7
21. Consider the following code snippet:
int size1 = 0;int size2 = 0;int num1[20];int num2[10];for (int cnt = 0; cnt < 5; cnt = cnt++){ num1[cnt] = cnt + 1; size1++; if (size2 < 4) { num2[cnt] = cnt + 1; size2++; }}What is the value of the size2 variable after executing the given code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 3
B) 5
C) 6
D) 4
Ans: DTitle: What is value of size2 variable after for loop modifies arrays?Difficulty: MediumSection Ref: 6.1
22. Consider the following code snippet:
vector vectseries(10);for (int i = 0; i < vectseries.size(); i++){ vectseries[i] = i + 1;}What value is stored in the 0th element of the vector?
A) 0
B) 1
C) 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 3
Ans: BTitle: What value is stored in vector[0] after this for loop initializes the vector?Difficulty: EasySection Ref: 6.7
23. Consider the following code snippet:
vector series1(10);vector series2(10);for (int i = 0; i < series1.size(); i++){ series1[i] = i + 1; series2[i] = series1[i] + 1;}What values are stored in the 0th element of the series1 and series2 vectors?
A) In the code snippet, series1 has 0 and series2 has 1.
B) In the code snippet, series1 has 1 and series2 has 0.
C) In the code snippet, series1 has 1 and series2 has 2.
D) In the code snippet, series1 has 1 and series2 has 1.
Ans: CTitle: What values are stored in vector[0] of two vectors after for loop initialization?Difficulty: MediumSection Ref: 6.7
24. What is the value of the variable sum in the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
vector series(10);int sum = 0;for (int cnt = 0; cnt < series.size(); cnt++){ series[cnt] = cnt + 1; sum = sum + series[cnt];}
A) 50
B) 55
C) 0
D) 1
Ans: BTitle: What is value of sum after for loop that initializes and sums vector?Difficulty: EasySection Ref: 6.7
25. Consider the following code snippet:
vector vect(5); // Line 1int sum = 0; // Line 2int avg = 0; // Line 3for (int cnt = 0; cnt < vect.size(); cnt++) // Line 4{ // Line 5 vect[cnt] = cnt; // Line 6 sum = sum + vect[cnt]; // Line 7} // Line 8Where should a statement for calculating the average of the vector values be added in the given code snippet?
A) Immediately after Line 4
B) Immediately after Line 6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Immediately after Line 7
D) Immediately after Line 8
Ans: DTitle: Where should statement for averaging vector values be added to snippet?Difficulty: MediumSection Ref: 6.7
26. What should be ensured for calculating the smallest value in a vector?
A) The vector contains at least one element.
B) The vector contains at least two elements.
C) The vector contains the maximum value in the first element.
D) The vector contains the least value in the first element.
Ans: ATitle: What should be ensured for calculating the smallest value in a vector?Difficulty: EasySection Ref: 6.7
27. Which one of the following is the correct code snippet for calculating the largest value in an integer vector of size 6?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) int max = 0;
for (int cnt = 1; cnt < vect.size(); cnt++)
{ if (vect[cnt] > max) { max = vect[cnt]; }}
B) int max = vect[0];
for (int cnt = 1; cnt max) { max = vect[cnt]; }}
C) int max = vect[1];
for (int cnt = 1; cnt max) { max = vect[cnt]; }}
D) int max = vect[0];
for (int cnt = 1; cnt > vect.size(); cnt++){ if (vect[cnt] >= max) { max = vect[cnt]; }}
Ans: BTitle: Which is correct code for calculating the largest value in vector of size 6?Difficulty: MediumSection Ref: 6.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
28. Consider the following code snippet:
vector num(3);num[0] = 1;num[1] = 2;num[2] = 1;int cnt = 0;for (int i = 0; i < num.size(); i++){ if (num[i] % 2 == 0) { cnt++; }}What is the value of the cnt variable after the execution of the given code snippet?
A) 1
B) 2
C) 0
D) No output
Ans: ATitle: What is value of cnt variable after this for loop modifies the vector?Difficulty: MediumSection Ref: 6.7
29. Consider the following code snippet:
vector num1;vector num2;… // Code here adds elements to the vectorsint cnt = 0;for (int i = 0; i < num1.size() && i < num2.size(); i++){ if (num1[i] == num2[i]) { cnt++; }}Which one of the following descriptions is correct for the given code snippet?
A) The code snippet finds the highest value out of the two vectors.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) The code snippet finds the lowest value out of the two vectors.
C) The code snippet compares the values of two vectors and stores the count of total matches found.
D) The code snippet adds the values of the two vectors.
Ans: CTitle: Which description is correct for this for loop that processes two vectors?Difficulty: EasySection Ref: 6.7[XXX Change to arrays]
30. Which one of the following code snippets accepts the integer input in an array named num1 and stores the odd integers of num1 in a vector named odnum?
A) int num1[10];
vector odnum;int data;for (int i = 0; i > data; num1[i] = data; if (num1[i] % 2 == 0) { odnum.push_back(num1[i]); }}
B) int num1[10];
vector odnum;int data;for (int i = 0; i > data; num1[i] = data; if (num1[i] % 2 != 0) { odnum.push_back(num1[i]); }}
C) int num1[10];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
vector odnum;int data;for int i = 0; i > data; num1.push_back(data); if (num1[i] % 2 == 0) { odnum[i] = num1[i]); }}
D) int num1[10];
vector odnum;int data;for (int i = 0; i > data; num1[i] = data; if (num1[i] % 2 == 0) { odnum[i] = num1[i]); }}
Ans: BTitle: Which code snippet fills one integer array and stores its odd integers in another array?Difficulty: MediumSection Ref: 6.2
31. Consider the following code snippet:
vector num1;int data;for (int i = 0; i > data; num1.push_back(data); if (data == 0 && num1.size() > 0) { num1.pop_back(); }}cout << "size is : " << num1.size();What is the output of the given code snippet if the user enters 1,2,0,0,1 as the input?
A) size is : 1
B) size is : 2
C) size is : 3
D) size is : 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: What is the vector.size after for loop with given input values?Difficulty: HardSection Ref: 6.7
32. Which one of the following statements is valid for declaring a vector as a function parameter?
A) A vector declared as a function parameter should be accompanied with its size.
B) A vector declared as a function parameter is a reference parameter by default.
C) An element of the vector cannot be modified in a function when the vector is declared as a parameter.
D) An element of the vector can be modified if declared using the & sign as a function parameter.

Ans: DTitle: Which statement is true about declaring a vector as a function parameter?Difficulty: EasySection Ref: 6.7
33. Which one of the following is a correct declaration for a function named passvect with the vector num of size 5 as a reference parameter?
A) void passvect(vector& num(5))
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) void passvect(vector num)
C) void passvect(vector& num)
D) void passvect(num)

Ans: CTitle: Which correctly declares a function with a vector of size 5 as a reference parameter?Difficulty: MediumSection Ref: 6.7

34. Which one of the following is a correct declaration for a function named passvect with the integer array num as a reference parameter, and its size in the integer parameter variable size?
A) void passvect(int[]& num, int size)
B) void passvect(int num, int size)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) void passvect(int &num[], int size)
D) void passvect(int num[], int size)

Ans: DTitle: Which correctly declares a function with an integer array as a reference parameter?Difficulty: MediumSection Ref: 6.3
35. Consider the following code snippet:
void check(vector chknum1){ int cnt = 0; for (int i = 0; i < chknum1.size(); i++) { if (chknum1[i] == 0) { cnt++; } } cout << "The total 0 values in the array are: " << cnt;}Which one of the following is true about the check function in the given code snippet?
A) The check function counts all the elements with value 0 in a vector passed as a parameter to the function.
B) The check function removes all the elements with value 0 from a vector passed as a parameter to the function.
C) The check function counts all the elements with value 0 in a vector passed as a parameter to a function and also returns the count.
D) The check function adds 0 to the elements of a vector as a parameter to a function and also returns the vector.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: Which is true about the check function in the given code snippet?Difficulty: MediumSection Ref: 6.3
36. Consider the following code snippet:
void check(int chknum1[], int size){ int cnt = 0; for (int i = 0; i < size; i++) { if (chknum1[i] == 0) { cnt++; } } cout << "The total 0 values in the array are: " << cnt;}Which one of the following is true about the check function in the given code snippet?
A) The check function counts all the elements with value 0 in an array as a parameter to the function.
B) The check function removes all the elements with value 0 from an array passed as a parameter to the function.
C) The check function counts all the elements with value 0 in an array passed as a parameter to a function and also returns the count.
D) The check function adds 0 to the elements of an array as a parameter to a function and also returns the array.
Ans: ATitle: Which is true about the check function in the given code snippet?Difficulty: MediumSection Ref: 6.3

37. Consider the following line of code for calling a function named my_fun:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
my_fun(dataset, vardata);Which one of the following function signatures is valid for my_fun, where dataset is an integer array and vardata is an integer variable?
A) void my_fun(dataset, vardata)
B) void my_fun(int dataset[], int vardata)
C) void my_fun(int vtdata[], vdata)
D) void my_fun(int vdata, int vtdata[])
Ans: BTitle: Which function signature is valid for the function called in this snippet?Difficulty: MediumSection Ref: 6.3

38. Consider the following line of code for calling a function named func1:
func1(vectdata, vardata);Which one of the following function signatures is valid for func1, where vectdata is an integer vector and vardata is an integer variable?
A) void func1(vectdata, vardata)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) void func1(vector vectdata, vardata)
C) void func1(vector vtdata, int vdata)
D) void func1(int vdata, vector vtdata)
Ans: CTitle: Which function signature is valid for the function called in this snippet?Difficulty: MediumSection Ref: 6.7

39. What is the output of the following code snippet?
int check(int mydata[], int size){ int sum = 0; for (int i = 0; i < size; i++) { sum = sum + mydata[i]; } return sum;}int main(){ int vdata[3]; int rsum; for (int cnt = 0; cnt < 3; cnt++) { vdata[cnt] = cnt + 1; } rsum = check(vdata, 3); cout << rsum; return 0;}
A) 6
B) 4
C) 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 0
Ans: ATitle: What is the output of this code that calls a function with an array as a parameter?Difficulty: HardSection Ref: 6.3

40. What is the output of the following code snippet?
int check(vector vectdata){ int sum = 0; for (int i = 0; i < vectdata.size(); i++) { sum = sum + vectdata[i]; } return sum;}int main(){ vector vdata(3); int rsum; for (int cnt = 0; cnt < 3; cnt++) { vdata.push_back(cnt + 1); } rsum = check(vdata); cout << rsum; return 0;}
A) 4
B) 2
C) 0
D) 6
Ans: DTitle: What is the output of this code that calls a function with a vector parameter?Difficulty: HardSection Ref: 6.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
41. Which one of the following statements is true about passing arrays to a function?
A) By default, arrays are passed by value to a function.
B) Arrays when updated in a called function are not reflected to the calling function.
C) By default, arrays are passed by reference to a function.
D) Arrays are passed by reference using the & sign.

Ans: CTitle: Which statement is true about passing arrays to a function?Difficulty: Easy Section Ref: 6.3
42. Which one of the following is the correct signature of a function named arrfunc whose function call is:
arrfunc(arrdt, num); // arrdt is an integer array of size 3 // num is an integer variable
A) void arrfunc(int ar[], int n)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) void arrfunc(r[], n)
C) void arrfunc(int n , int ar[])
D) void arrfunc(int ar , int n)
Ans: ATitle: Which function signature is valid for the function called in this snippet?Difficulty: MediumSection Ref: 6.3
43. Why is the following function signature invalid?
int[] func(int ar[], int num[])
A) Functions can use only void as a return type.
B) Functions cannot have an array as a return type.
C) Functions cannot have an array as a parameter.
D) Functions cannot have two array parameters.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: BTitle: Why is the following function signature invalid?Difficulty: MediumSection Ref: 6.3

44. Consider the following code snippet:
int cnt = 0;int numarray[2][3];for (int i = 0; i < 3; i++){ for (int j = 0; j < 2; j++) { numarray[j][i] = cnt; cnt++; }}What is the value of numarray[1][2] after the code snippet is executed?
A) 2
B) 5
C) 3
D) 4
Ans: BTitle: What is the value of this 2D array element after the nested for loop is executed?Difficulty: HardSection Ref: 6.6
45. How many elements can be stored in an array of dimension 2 by 3?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 2
B) 3
C) 5
D) 6
Ans: DTitle: How many elements can be stored in an array of dimension 2 by 3?Difficulty: EasySection Ref: 6.6
46. Which one of the following statements is the correct definition for a two-dimensional array of 20 rows and 2 columns of the type integer?
A) int num[20][2];
B) int num[2][20];
C) int num[20,2];
D) int num[2,20];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: ATitle: Which is correct definition for a 2D integer array of 20 rows and 2 columns?Difficulty: MediumSection Ref: 6.6
47. Consider the following code snippet:
int numarray[2][3] = { { 3, 2, 3 }};cout << numarray[0][0];cout << numarray[1][0];What is the output of the given code snippet?
A) 00
B) 31
C) 30
D) 03
Ans: CTitle: What is output of snippet that initializes 2D array and displays two of its elements?Difficulty: HardSection Ref: 6.6
48. Which one of the following is the correct definition for initializing data in a two-dimensional array of three rows and two columns?
A) int arr[2][3] =
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
{ 1, 1, 1 }, { 2, 2, 2 },};
B) int arr[3][2] =
{
{ 1, 1 }, { 2, 2 }, { 3, 3 }};
C) int arr[3][2] =
{
{ 1, 1 } { 2, 2 } { 3, 3 }};
D) int arr[2][3] =
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{ 1, 1, 1 } { 2, 2, 2 } { 3, 3, 3 }};
Ans: BTitle: Which is correct definition for initializing a 2D array of three rows and two columns?Difficulty: HardSection Ref: 6.6
49. Which one of the following statements is correct for displaying the value in the second row and the third column of a two-dimensional, size 3 by 4 array?
A) cout << arr[1][2];
B) cout << arr[2][3];
C) cout << arr[2][1];
D) cout << arr[3][2];
Ans: ATitle: Which statement displays the value in the second row and third column of a 2D 3 by 4 array?Difficulty: MediumSection Ref: 6.6
50. Consider the following code snippet:
int arr[2][3] = { { 13, 23, 33 }, { 14, 24, 34 }};What is the appropriate statement to display the value 24 from the given array?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) cout << arr[1][2];
B) cout << arr[2][2];
C) cout << arr[1][1];
D) cout << arr[2][1];
Ans: CTitle: Which statement displays the value 24 from the 2D array initialized here?
Difficulty: EasySection Ref: 6.6
51. Consider the following code snippet:
int val = arr[0][2];Which value of arr is stored in the val variable?
A) The value in the first row and the second column
B) The value in the first row and the first column
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The value in the first row and the third column
D) The value in the third row and the second column
Ans: CTitle: Which value of the 2D array arr is stored in arr[0][2]?Difficulty: EasySection Ref: 6.6
52. Consider the following code snippet:
int arr[2][3] = { { 1, 2, 3 }, { 4, 5, 6 }};int val = arr[0][2] + arr[1][2];cout << val;What is the output of the given code snippet on execution?
A) 5
B) 7
C) 9
D) 10
Ans: CTitle: What is the output of this snippet that sums two values in a 2D array?Difficulty: MediumSection Ref: 6.6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
53. Consider an array of size 3 by 4. What is the offset to reach the array[2][1] element?
A) 9
B) 8
C) 10
D) 7
Ans: ATitle: What is the offset to reach the array[2][1] element in a 3 by 4 array?Difficulty: MediumSection Ref: 6.6
54. Which one of the following is a valid signature of a function with an integer two-dimensional array parameter of size 10 x 10?
A) void func(int arr[][])
B) void func(int arr[10][])
C) void func(int arr[][10])
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) void func(int arr[10, 10])
Ans: CTitle: Which signature is valid for a function with a 2D array parameter of size 10 x 10?Difficulty: MediumSection Ref: 6.6
55. Consider the following line of code:
int somearray[50];Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?
A) cout << somearray[28];
B) cout << somearray(28);
C) cout << somearray(27);
D) cout << somearray[27];
Ans: DTitle: Which code displays the 28th element of somearray?Difficulty: EasySection Ref: 6.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
56. Identify the correct statement for defining an integer array named numarray of ten elements.
A) int numarray[9];
B) int numarray[10];
C) int numarray[];
D) int [10]numarray;

Ans: BTitle: Which statement defines integer array numarray with ten elements?Difficulty: EasySection Ref: 6.1

57. Which one of the following statements is an invalid initialization of an array named somearray?
A) int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
C) int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
D) int somearray[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
Ans: BTitle: Which array initialization statement is invalid?Difficulty: MediumSection Ref: 6.1

58. Consider the following code snippet:
int myarray[] = { 10, 20, 30, 40, 50 };cout << myarray[2];cout << myarray[3];What is the output of the code snippet?
A) 1050
B) 2030
C) 3040
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 4050
Ans: CTitle: What are values of the elements at the given array indexes?Difficulty: MediumSection Ref: 6.1

59. Consider the following code snippet:
int marks[3] = { 90, 45, 67 };for (int i = 0; i <= 3; i++){ cout << marks[i] << endl;}What is the result of executing this code snippet?
A) The code snippet does not give any output.
B) The code snippet displays all the marks stored in the array without any redundancy.
C) The code snippet has a bounds error or displays redundant data.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The code snippet executes an infinite loop.

Ans: CTitle: What is output of for loop that traverses given array?Difficulty: Medium
Section Ref: 6.1
60. Consider the following code snippet:
int mymarks[10];int total;for (int cnt = 1; cnt <= 10; cnt++){ cout <> mymarks[cnt]; total = total + mymarks[cnt];}cout << total;Which one of the following outputs is displayed on executing the given code snippet?
A) The code snippet displays the total marks of all ten subjects.
B) The code snippet gives a runtime time error, not an output.
C) The code snippet has a bounds error or shows redundant data.
D) The code snippet displays zero.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: CTitle: Which is result of for loop that fills an array and totals its elements?Difficulty: HardSection Ref: 6.1
61. What is the result of the following definition of a vector?
vector points;
A) The statement causes a compile-time error as the size of the vector is not defined.
B) The statement creates a vector of size 0.
C) The statement creates a vector with unlimited size.
D) The statement creates a vector of size 1.
Ans: BTitle: What is the result of this definition of a vector?Difficulty: MediumSection Ref: 6.7
62. Consider the following code snippet:
vector somedata;somedata.push_back(10);What is the size of the vector somedata after the given code snippet is executed?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 0
B) 1
C) 10
D) 2

Ans: BTitle: What is the size of the given vector after push_back(10)?Difficulty: Easy
Section Ref: 6.7

63. What is the valid range of index values for an array of size 10?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 0 to 10
B) 1 to 9
C) 1 to 10
D) 0 to 9

Ans: DTitle: What is the range of index values for an array of size 10?Difficulty: EasySection Ref: 6.1
64. Consider the following code snippet:
int somearray[6];for (int i = 1; i < 6; i++){ somearray[i] = i + 1;}Which one of the following statements is correct about the given code snippet?
A) The for loop initializes all the elements of the array.
B) The for loop initializes all the elements except the first element.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The for loop initializes all the elements except the last element.
D) The for loop initializes all the elements except the first and last elements.

Ans: BTitle: Which statement is true about this for loop that initializes an array?Difficulty: Hard
Section Ref: 6.1
65. Consider the following code snippet:
int mynum[5];for (int i = 1; i < 5; i++){ mynum[i] = i + 1; cout << mynum[i];}What is the output of the given code snippet?
A) 2345
B) 1234
C) 1345
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 1111
Ans: ATitle: What is output of this for loop that traverses/displays array elements?Difficulty: Medium
Section Ref: 6.1
66. Consider the following code snippet:
int number[3]; // Line 1number[3] = 5; // Line 2Which one of the following statements is correct for the given code snippet?
A) Line 2 declares and initializes an array of three elements with value 5.
B) Line 2 causes a bounds error because 3 is an invalid index number.
C) Line 2 initializes the third element of the array with value 5.
D) Line 2 initializes all the elements of the array with value 5.
Ans: BTitle: Which statement is true for snippet with array bounds error?Difficulty: EasySection Ref: 6.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
67. What is the output of the following code snippet?
vector num(4);num.push_back(4);cout << num.size();
A) 1
B) 3
C) 4
D) 5
Ans: DTitle: What is value of vector.size after this snippet with push_back?Difficulty: EasySection Ref: 6.7
68. Your program needs to store a sequence of integers of unknown length. Which of the following can you use?
A) An array declared as int marks[];
B) A vector declared as vector marks;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) An array declared as int marks[10000]; with a companion variable.
D) An array declared as int marks[int size] where size can be set later.
Ans: BTitle: Which can you use to store a sequence of integers of unknown length?Difficulty: EasySection Ref: 6.7

69. Consider the following code snippet:
const int SIZE = 5;
int data_array[SIZE];
for (int i = 0; i < SIZE; i++){ data_array[i] = 2 * (i – 1);}What value is stored in position 2 of the array?
A) 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 1
C) 2
D) 3
Ans: CTitle: What value is stored in position 2 of the array after this for loop executes?Difficulty: MediumSection Ref: 6.2

70. Consider the following code snippet:
vector vectarr(5);for (int i = 0; i < vectarr.size(); i++){ vectarr[i] = i + 3;}What value is stored in the 0th element of the vector?
A) 0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 3
C) 6
D) 9
Ans: BTitle: What value is stored in vector[0] after this for loop initializes the vector?Difficulty: EasySection Ref: 6.7

71. What should be ensured for calculating the largest value in a vector?
A) The vector contains at least one element.
B) The vector contains at least two elements.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The vector contains the minimum value in the first element.
D) The vector contains the maximum value in the first element.
Ans: ATitle: What should be ensured for calculating the largest value in a vector?Difficulty: EasySection Ref: 6.7

72. Which one of the following is the correct code snippet for calculating the largest value in an integer array of size 100?
A) int maximum = 0;
for (int counter = 1; counter < 100; counter++)
{ if (intarray[counter] > maximum) { maximum = intarray[counter]; }}
B) int maximum = intarray[0];
for (int counter = 1; counter maximum) { maximum = intarray[counter]; }}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) int maximum = intarray[1];
for (int counter = 1; counter maximum) { maximum = intarray[counter]; }}
D) int maximum = intarray[0];
for (int counter = 1; counter > 100; counter++){ if (intarray[counter] >= maximum) { maximum = intarray[counter]; }}
Ans: BTitle: Which is correct code for calculating the largest value in an array of size 100?Difficulty: MediumSection Ref: 6.3

73. Which one of the following is the correct code snippet for calculating the largest value in an integer vector?
A) int maximum = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int counter = 1; counter < vecarray.size(); counter++)
{ if (vecarray[counter] > maximum) { maximum = vecarray[counter]; }}
B) int maximum = vecarray[0];
for (int counter = 1; counter maximum) { maximum = vecarray[counter]; }}
C) int maximum = vecarray[1];
for (int counter = 1; counter maximum) { maximum = vecarray[counter]; }}
D) int maximum = vecarray[0];
for (int counter = 1; counter > vecarray.size(); counter++){ if (vecarray[counter] >= maximum) { maximum = vecarray[counter]; }}
Ans: BTitle: Which is correct code for calculating the largest value in vector?Difficulty: MediumSection Ref: 6.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

74. Consider the following code snippet:
int somenum[3] = { 3, 2, 1 };
int cnt = 0;for (int count = 0; count < 3; count++){ if (somenum[count] % 2 == 0) { cnt++; }}What is the value of the cnt variable after the execution of the given code snippet?
A) 1
B) 2
C) 3
D) 4
Ans: ATitle: What is value of cnt variable after this for loop modifies the vector?Difficulty: MediumSection Ref: 6.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
75. Consider the following code snippet:
vector somenum(5);somenum[0] = 1;somenum[1] = 2;somenum[2] = 1;int cnt = 0;for (int count = 0; count < somenum.size(); count++){ if (somenum[count] % 2 == 0) { cnt++; }}What is the value of the cnt variable after the execution of the given code snippet?
A) 1
B) 2
C) 3
D) unpredictable result
Ans: CTitle: What is value of cnt variable after this for loop modifies the vector?Difficulty: MediumSection Ref: 6.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
76. Which one of the following code snippets accepts the integer input in a vector named num1 and stores the even integers of num1 in another vector named evennum?
A) vector num1;
vector evennum;int data;for (int i = 0; i > data; num1.push_back(data); if (num1[i] % 2 == 0) { evennum.push_back(num1[i]); }}
B) vector num1;
vector evennum;int data;for (int i = 0; i > data; num1.push_back(data); if (num1[i] % 2 != 0) { evennum.push_back(num1[i]); }}
C) vector num1;
vector evennum;int data;for int i = 0; i > data; num1.push_back(data); if (num1[i] % 2 != 0) { evennum[i] = num1[i]); }}
D) vector num1;
vector evennum;int data;for (int i = 0; i > data; num1[i] = data; if (num1[i] % 2 == 0) { evennum[i] = num1[i]); }}
Ans: ATitle: Which code snippet fills one integer vector and stores its even integers in another array?Difficulty: MediumSection Ref: 6.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
77. Which one of the following is a correct declaration for a function named passvect with the vector parameter mynum of size 10, so that the function modifies the contents of the actual parameter mynum?
A) void passvect(vector& mynum(10))
B) void passvect(vector mynum)
C) void passvect(vector& mynum)
D) void passvect(mynum)

Ans: CTitle: Which correctly declares a function that can modify the contents of its vector parameter of size 10?Difficulty: Medium
Section Ref: 6.7
78. Consider the following code snippet:
int cnt = 0;int myarray[4][5];for (int i = 0; i < 5; i++){ for (int j = 0; j < 4; j++) { myarray[j][i] = cnt; cnt++; }}What is the value of myarray[1][2] after the code snippet is executed?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 8
B) 9
C) 19
D) 11
Ans: BTitle: What is the value of this 2D array element after the nested for loop is executed?Difficulty: HardSection Ref: 6.6
79. How many elements can be stored in an array of dimension 5 by 6?
A) 5
B) 6
C) 11
D) 30
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: DTitle: How many elements can be stored in an array of dimension 5 by 6?Difficulty: Easy
Section Ref: 6.6

80. How many integer elements can be stored in the array myarr declared below?
int myarr[10][8];
A) 10
B) 80
C) 18
D) 72
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: BTitle: How many elements can be stored in a 2D array given the declaration?Difficulty: Easy
Section Ref: 6.6
81. Consider the following code snippet:
int numarray[2][3] = { { 8, 7, 6 }};cout << numarray[0][0];cout << numarray[1][0];What is the output of the given code snippet?
A) 00
B) 87
C) 80
D) 08
Ans: CTitle: What is output of snippet that initializes 2D array and displays two of its elements?Difficulty: HardSection Ref: 6.6
82. Which one of the following statements is correct for displaying the value in the third row and the fourth column of a two-dimensional, size 5 by 6 array?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) cout << arr[2][3];
B) cout << arr[3][4];
C) cout << arr[3][2];
D) cout << arr[4][3];
Ans: ATitle: Which statement displays the value in the second row and third column of a 2D 5 by 6 array?Difficulty: MediumSection Ref: 6.6
83. Consider the following code snippet:
int arr[4][5] = { { 1, 2, 3 }, { 4, 5, 6 }};int val = arr[1][2] + arr[1][3];cout << val;What is the output of the given code snippet on execution?
A) 5
B) 6
C) 7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 9
Ans: BTitle: What is the output of this snippet that sums two values in a 2D array?Difficulty: MediumSection Ref: 6.6

84. Consider the following code snippet:
int arr[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }};int val = arr[0][2] + arr[2][0];cout << val;What is the output of the given code snippet on execution?
A) 3
B) 4
C) 5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 6
Ans: ATitle: What is the output of this snippet that sums two values in a 2D array?Difficulty: MediumSection Ref: 6.6

85. What is the output of the following code snippet?
int firstarray[5] = { 4, 2, 6, 0, 1 };
int indexarray[5] = { 4, 2, 1, 0, 3 };

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 4; i >= 0; i–)
{
cout << firstarray[indexarray[i]];
}
A) 10624
B) 30124
C) 04261
D) 14240
Ans: CTitle: What is the output of this snippet that sums two values in a 2D array?Difficulty: MediumSection Ref: 6.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

86. What is the output of the following code snippet?
int my_fun (int A[], int size)
{
int result = 0;
for (int i = 0; i < size; i++)
{
result = result + A[i];
}
return result;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
int main()
{
int myarr[10] = { 5, 6, 10, 1, 2, 4, 8, 1, 2, 1 };
for (int i = 0; i < 3; i++)
{
cout << my_fun(myarr, i);
}}
A) No output
B) 0511
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 056
D) 000
Ans: BTitle: What is the output of this code snippet that calls a function with an array as a parameter?Difficulty: MediumSection Ref: 6.3

87. What is the output of the following code snippet?
int my_fun(int A[], int size)
{
int result = 0;
for (int i = 0; i < size; i++)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
result = result + A[i];
}
return result;
}
int main()
{
int myarr[10] = { 2, 4, 10, 1, 2, 4, 8, 1, 2, 1 };
for (int i = 0; i < 3; i++)
{
cout << my_fun(myarr, myarr[i]);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}}
A) 026
B) 6435
C) 61735
D) 600
Ans: CTitle: What is the output of this code snippet that calls a function with an array as a parameter?Difficulty: HardSection Ref: 6.3

88. In the following code fragment, the variables SIZE and count serve what roles?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
const int SIZE = 100;
int data[SIZE];
int count = 0;
int value;
while ((count > value))
{
data[count] = value;
count++;
}
A) SIZE is the capacity of the array; count is the number of elements currently used
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) SIZE is the number of elements used in the array; count is the array capacity
C) SIZE is the capacity of the array; count is the number of elements that are equal to zero
D) SIZE is the number of elements unused in the array; count is the number of inputs
Ans: ATitle: What roles do variables count and SIZE play in this snippet?Difficulty: EasySection Ref: 6.1

89. What is the error in the following code snippet?
const int WORDCOUNT = 100;
string words[WORDCOUNT];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i <= WORDCOUNT; i++)
{
cout << words[i] << endl;
}
A) Cannot define an array of strings
B) Infinite loop
C) Array index out of bounds
D) Skips elements in the array
Ans: CTitle: What is the error in the following code snippet (array of strings)?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 6.1

90. Which lines of code correctly complete the linear search of an array of integers for the value 42?
const int SIZE = 100;
int values[SIZE];
// Assume array has been filled with integers
// …
bool found = false;
int pos = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (pos < SIZE && !found)
{
// CODE TO COMPLETE GOES HERE
}
A) if (values[pos] == 42)
{
found = true;
}
else
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
pos++;
}
B) if (values[pos] == 42)
{
found = true;
pos++;
}
C) if (values[++pos] == 42)
{
found = true;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
D) if (values[pos] != 42)
{
found = true;
}
else
{
pos++;
}
Ans: ATitle: Which code correctly completes the linear search of the array?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 6.2

91. Which code correctly swaps the integer values stored in the array data at positions first and second?
A) int temp = data[first];
data[first] = temp;
data[second] = data[first];
B) int temp = data[first];
data[first] = data[second];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
data[second] = temp;
C) int temp = data[first];
data[first] = data[temp];
data[second] = temp;
D) int temp = data[first];
data[first] = data[second];
data[second] = data[first];
Ans: BTitle: Which code correctly swaps two values stored in an array?Difficulty: Medium
Section Ref: 6.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

92. Which of the following is the correct first line of a function that swaps two elements of an array passed in as a parameter?

A) void myswap(int A[], int size)
B) void myswap(int &A[], int i, int j)
C) void myswap(int A[], int i, int j)
D) void myswap(int A, int i, int j)
Ans: CTitle: Which is the correct first line of a swap function?Difficulty: Medium
Section Ref: 6.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
93. Which of the following is the correct first line of a function that swaps two elements of an array passed in as a parameter?

A) void myswap(const int A[], int size)
B) void myswap(const int A[], int index1, int index2)
C) void myswap(int A[], int index1, int index2)
D) void myswap(int A, int index1, int index2)
Ans: CTitle: Which is the correct first line of a swap function?Difficulty: Medium
Section Ref: 6.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
94. The selection sort uses two primary operations to put the elements of an array in order:
A) find the minimum; and insert
B) find the minimum; and swap
C) divide and conquer; and swap
D) insert; and copy
Ans: BTitle: Which two primary operations are used in selection sort?
Difficulty: Medium
Section Ref: 6.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
95. The binary search on an array requires that
A) The array elements be in order
B) The array elements be in random order
C) The element that is being searched for must always be in the array
D) The array be two dimensional
Ans: ATitle: What is a condition for binary search in an array?
Difficulty: Medium
Section Ref: 6.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
96. Why is it unnecessary to explicitly use the & symbol when passing a one-dimensional array as a reference parameter?
A) It is not allowable to pass arrays by reference in C++
B) Only the elements of an array can be passed by reference
C) Only two-dimensional arrays can be passed by reference
D) One dimensional arrays are always passed by reference in C++
Ans: DTitle: What are the conditions for parameter passing for one-dimensional arrays?Difficulty:Section Ref: 6.3

97. The consideration of boundary conditions for a function implementation means that
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) It is guaranteed that no array bounds error can ever occur
B) The function correctly handles exceptional situations
C) Helper functions are used when needed
D) Performance run times fall within acceptable boundaries
Ans: BTitle: What does it mean to consider boundary conditions?
Difficulty: Easy
Section Ref: 6.4

98. Consider a function that takes an array of integers and returns the sum of all the elements. The case where the function is called with an array of size zero is called a
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Out-of-bounds error
B) Irregularity
C) Syntax error
D) Boundary condition
Ans: DTitle: What is it called when a function is invoked with an array size of zero?
Difficulty: Easy
Section Ref: 6.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
99. The telephone book is a physical object that can help understand algorithms such as
A) Sorting
B) Searching
C) Finding the maximum
D) Monte Carlo methods
Ans: BTitle: What algorithms can be understood through the phone book as a physical object?
Difficulty: EasySection Ref: 6.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
100. Which is true when a 2D array is used as a function parameter?
A) Only the row size must be a constant provided as an argument to the function
B) Only the column size must be a constant provided as an argument to the function
C) Both the row and column size must be constants provided as arguments to the function
D) Neither the row nor the column size are necessary
Ans: BTitle: What is needed in order to pass a 2D array as a parameter to a function?
Difficulty: Easy
Section Ref: 6.6

1. Which statement is true about an uninitialized pointer?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) It may point to a memory location that a program does not own
B) It always has the value null
C) It will always point to a memory location that a program owns
D) It will never cause a problem in a program

Ans: A
Title: Which statement is true about an uninitialized pointer?
Difficulty: Easy
Section Ref: 7.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

2. A pointer describes which of the following?

A) What a certain value in memory is
B) Where a certain value in memory is
C) When a certain value is in memory
D) The size of a certain value in memory

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: A pointer describes which of the following?
Difficulty: Easy
Section Ref: 7.1

3. Which of the following statements is true about pointers?

A) Pointers contain values as well as addresses of variables.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Pointers contain address locations of variables.
C) Pointers do not have any address location of their own.
D) Pointers occupy permanent storage locations inside the hard disk.

Ans: B
Title: Which statement is true about pointers?
Difficulty: Medium
Section Ref: 7.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

4. What is true about the statement given below?
int* choice;

A) choice is an integer variable
B) choice contains the memory location of an integer variable
C) choice can store two memory addresses simultaneously
D) choice can also store a string value

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is true about (variable declaration)?
Difficulty: Easy
Section Ref: 7.1

5. Which of the following is a legally correct way of declaring a variable that is a pointer to an integer?

A) int* ptr
B) pointer ptr
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) int& ptr
D) int ptr*

Ans: A
Title: Which statement declares a variable that is a pointer to an integer?
Difficulty: Medium
Section Ref: 7.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
6. Consider the code snippet below.
int ch = 100;
Which of the following is a legally correct way of obtaining the memory location of ch and printing it (the memory location) to standard output, based on the given code snippet?

A) cout << ch << endl;
B) cout << *ch << endl;
C) cout << &ch << endl;
D) cout << *(&ch) << endl;

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement gets the memory location of ch and prints it to standard output?
Difficulty: Easy
Section Ref: 7.1

7. Consider the code snippet below.
int ch = 100;
int* ptr = &ch;
Which of the following observations are true based on the code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) ptr stores the value of ch
B) ptr stores the address of ch
C) &ptr gives the address of ch
D) &ptr gives the value of ch

Ans: B
Title: Which is true about snippet (with assignment to pointer)?
Difficulty: Medium
Section Ref: 7.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

8. What is displayed when you execute the following code snippet?
int ch = 100;
cout << &ch << endl;

A) The value of ch
B) The memory location of ch
C) The value at the memory location of 100
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) None of the listed items

Ans: B
Title: What is displayed by snippet (sending &ch to cout)?
Difficulty: Medium
Section Ref: 7.1

9. Consider the code snippet below.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int ch;
ch = 100;
int* ptr = &ch;
Which of the following statements represents a legal way of obtaining the value that ptr points to?

A) ptr
B) *ptr
C) &ptr
D) *(&ptr)

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: Which statement gets the value that ptr points to?
Difficulty: Easy
Section Ref: 7.1

10. What is the output of the following code snippet?
int num = 0;
int* ptr = &num;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
*ptr = 80;
num = 90;
cout << *ptr << endl;

A) 0
B) 80
C) 90
D) the address of num

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of snippet (assigning values and addresses)?
Difficulty: Medium
Section Ref: 7.1

11. What is the output of the following code snippet?
int num = 0;
int* ptr = &num;
num = 5;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
*ptr = *ptr + 5;
cout << num << " " << *ptr << endl;

A) 5 5
B) 5 10
C) 10 5
D) 10 10

Ans: D
Title: What is output of snippet (dereferencing pointers)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.1

12. Which of the following is a common pointer error?

A) Setting a pointer variable to a new value
B) Setting a pointer variable to NULL
C) Using a pointer that has not been initialized
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Dereferencing a pointer

Ans: C
Title: Which is a common pointer error?
Difficulty: Easy
Section Ref: 7.1

13. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int* ptr;
*ptr = *ptr + 5;
cout << *ptr << endl;

A) There is no output due to compilation errors.
B) The address stored in ptr
C) 5
D) It results in an unpredictable error when the code is run because it uses an uninitialized pointer

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the output of snippet (with pointer variable)?
Difficulty: Medium
Section Ref: 7.1

14. What is the problem with the following code snippet?
double* acc_ptr;
*acc_ptr = 1000;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) There is no problem.
B) There is a compilation error.
C) The acc_ptr variable is never initialized.
D) The second statement assigns an integer to a pointer.

Ans: C
Title: What is wrong with snippet (with pointer variable)?
Difficulty: Medium
Section Ref: 7.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

15. What is the output of the following code snippet?
int* score = NULL;
cout << *score << endl;

A) There is no output due to a compilation error.
B) 0
C) NULL
D) It results in an illegal data access error.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: What is the output of snippet (with NULL pointer)?
Difficulty: Medium
Section Ref: 7.1

16. What is the output of the following code snippet?
int* num = NULL;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << num << endl;

A) There is no output due to a compilation error.
B) An address of 0
C) “NULL”
D) There are no compilation errors but when the code snippet is run, it results in an illegal data access error.

Ans: B
Title: What is the output of snippet (with NULL pointer)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.1

17. Which location of the array arr does ptr point to right after you assign an array to a pointer variable, as shown in the following code snippet?
int arr[10];
int* ptr = arr;

A) arr[0]
B) arr[1]
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) arr[10]
D) You cannot assign an array to a pointer.

Ans: A
Title: Which array location does ptr point to (after array assigned to pointer)?
Difficulty: Easy
Section Ref: 7.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
18. What is the output of the code snippet given below?
int arr[5] = { 1, 2, 3, 4, 5 };
int* ptr = arr;
cout << "arr[0] << " contains a value of " << *ptr << endl;

A) There is no output due to a compilation error.
B) There is no output due to a run-time error.
C) arr[0] contains a value of 0
D) arr[0] contains a value of 1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is output of snippet (that uses pointer to access array value)?
Difficulty: Medium
Section Ref: 7.2

19. Given the following code snippet, what is true about the statement ptr++?
int arr[5] = { 1, 2, 3, 4, 5 };
int* ptr = arr;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
ptr++;

A) ptr now points to arr[0];
B) ptr now points to arr[1];
C) ptr++ results in a compilation error
D) ptr++ results in a run-time error

Ans: B
Title: What is true about ptr++ in snippet (that assigns array to ptr)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.2

20. What is the output of the following code snippet?
int arr[5] = { 1, 2, 3, 4, 5 };
int* ptr = arr;
ptr = ptr + 2;
cout << *ptr << endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) There is no output due to a compilation error.
B) 1
C) 2
D) 3

Ans: D
Title: What is output of snippet (that uses pointer arithmetic)?
Difficulty: Hard
Section Ref: 7.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

21. Which of the following options does the array/pointer duality law state?

A) a[n] is the same as *a + n
B) a[n] is the same as a->n
C) a[n] is the same as *(a + n)
D) a[n] is the same as (a + *n)

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which does the array/pointer duality law state?
Difficulty: Easy
Section Ref: 7.2

22. Consider the code snippet below.
int arr[5] = { 1, 2, 3, 4, 5 };
Which of the following is the value of *(arr + 2)?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 1
B) 2
C) 3
D) 4

Ans: C
Title: What is output of snippet (that uses array/pointer duality)?
Difficulty: Medium
Section Ref: 7.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

23. What is the output of the code snippet given below?
char arr[5] = { ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ };
char* ptr = arr;
ptr = ptr + 4;
arr[4] = ‘y’;
cout << *ptr << endl;

A. a
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B. o
C. y
D. u

Ans: C
Title: What is output of snippet (that uses array/pointer duality)?
Difficulty: Hard
Section Ref: 7.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

24. Which of the following statements hold true when you want to pass an array to a function?

A) You cannot pass an array to a function.
B) You have to pass all the values of the array as parameters to the function.
C) A function always receives the starting address of the array.
D) The function cannot make changes to the array.

Ans: C
Title: Which statement is true about passing an array to a function?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 7.2

25. Suppose that you declare an array int num[10]. Assuming the function declaration statement given below, what would you use to pass the array to the given function?
int sum_array(int arr[])
{

}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) sum_array(num)
B) sum_array(num[0])
C) sum_array(*num)
D) sum_array(&num)

Ans: A
Title: What (syntax) would you use to pass an array to this function?
Difficulty: Medium
Section Ref: 7.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

26. A programmer writes the sum_array function, as shown in the following code snippet. The programmer was surprised to find incorrect output from the main program. What is wrong with the following code snippet?
int sum_array(int arr[], int size)
{
int result = 0;
for (int i = 0; i < size; i = i + 2)
{
result = result + arr[i];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
return result;
}
int main()
{
int sum_array(int arr[], int size);
int num[5] = { 1, 2, 3, 4, 5 };
int sum = sum_array(num, 7);
cout << "Sum: " << sum << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) The sum_array function works only with an array with an even number of values.
B) It is not possible to pass an array as an argument to a function.
C) The main function passes an incorrect size for the num array.
D) The main function does not initialize the num array correctly before passing it to the sum_array function.

Ans: C
Title: What is wrong with this code (that passes an array to a function)?
Difficulty: Hard
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.2

27. Which of the following options denotes the newline character?

A) “l”
B) ‘l’
C) ‘n’
D) ‘r’
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Title: Which denotes the newline character?
Difficulty: Easy
Section Ref: 7.3

28. What is the output of the following code snippet?
char name[] = “Harry Houdini”;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
name[3] = ‘v’;
cout << name << endl;

A) Harry Houdini
B) Harvy Houdini
C) Havry Houdini
D) Harry Houdiniv

Ans: B
Title: What is output of snippet (with array of char values)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.3

29. Which of the following is true about the chars variable?
char chars[] = “Hello World”;

A) chars is an array of size 11, and the last value in the array is “d.”
B) chars is an array of size 12, and the last value in the array is “d.”
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) chars is an array of size 11, and the last value in the array is 0.
D) chars is an array of size 12, and the last value in the array is 0.

Ans: D
Title: Which is true about (char array initialized with literal string)?
Difficulty: Easy
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
30. What is the output of the following code snippet?
int main()
{
int i = 5;
char* name = “Steven Black”;

cout << name[i] << endl;
return 1;
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) n
B) en
C) Black
D) The program does not compile due to a syntax error.

Ans: A
Title: What is output of snippet (with pointer to char array)?
Difficulty: Medium
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

31. Many of the C++ library functions expect arguments to be C strings. Which of the following declares a C string?

A) char
B) char*
C) string
D) string*

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which of these declares the old C style of character string?
Difficulty: Easy
Section Ref: 7.3

32. What is the output of the following code snippet?
int marks = 0;
char* str_marks = “350”;
marks = atoi(str_marks);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << marks << endl;

A) 3
B) 350
C) There is no output due to a compilation error.
D) There is no output due to a run-time error.

Ans: B
Title: What is output of snippet (that uses atoi)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.3

33. What is the output of the following code snippet?
int marks = 0;
string str_marks = “350”;
marks = atoi(str_marks);
cout << marks << endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) 0
B) 350
C) There is no output due to a compilation error.
D) There is no output due to a run-time error.

Ans: C
Title: What is output of snippet (with string argument for atoi)?
Difficulty: Medium
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

34. Which of the following functions enables you to convert a string object to a char* object?

A) atoi()
B) str()
C) c_str()
D) c_string()

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which function converts a string object to a char* object?
Difficulty: Easy
Section Ref: 7.3

35. You have declared the following string variable: string name = “Houdini”; Which of the following statements is a legal assignment statement?

A) string* strp = name.c_str();
B) string str = c_str(name);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) const char* cstr = name.c_str();
D) const char* cstr = c_str(name);

Ans: C
Title: Which is a legal assignment statement (using c_str())?
Difficulty: Medium
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
36. Which of the following statement(s) represents a valid declaration of a C++ string variable?

A) string str = null;
B) string str = ”;
C) string str = “aeiou”;
D) string str = { ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ };

Ans: C
Title: Which is a valid declaration of a C++ string variable?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.3

37. How can you access the character ‘r’ in the following C++ string?
string name = “Peter”;

A) char last = name[4];
B) char last = name[5];
C) char last = name.substr(5);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) char last = name.substr(4, 5);

Ans: A
Title: How can you access the character ‘r’ in this C++ string?
Difficulty: Easy
Section Ref: 7.3

38. What is output of the code snippet given below?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
string name = “Oscar DeGama”;
cout << name[7] << name[8] << name[9] << endl;

A) There is no output due to compilation error.
B) DeG
C) eGa
D) Gam

Ans: C
Title: What is output of code (using [] operator with C++ string)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.3

39. What is the name for the large storage area that is managed by the run-time system?
A) stack
B) RAM
C) pile
D) heap
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: What is name of large storage area managed by the run-time system?
Difficulty: Easy
Section Ref: 7.4

40. Which of the following is a legal statement to dynamically allocate memory for an array whose size is not known until run time?
int size; // Assume that size is set at run time
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) double[] darray = new double[size];
B) int* intarray = new int[size];
C) int* intptr = int[size];
D) It is not possible to dynamically allocate memory for an array, the size must be known at compile time.

Ans: B
Title: Which is correct statement to dynamically allocate memory for array?
Difficulty: Medium
Section Ref: 7.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

41. What is the difference between a heap array and an array variable?
A) The heap array must have a fixed size when it is declared. The array variable can have a dynamic size, determined at run-time.
B) The array variable must have a fixed size when it is declared. The heap array can have a dynamic size, determined at run-time
C) Neither the heap array nor the array variable can be dynamically sized.
D) Both the heap array and the array variable can be dynamically sized.

Ans: B
Title: Which statement is correct about the difference between a heap array and an array variable?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.4

42. Which of the following operators is used to allocate memory from the heap?

A) new
B) alloc
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) new[]
D) []

Ans: A
Title: Which operator is used to allocate memory from the heap?
Difficulty: Easy
Section Ref: 7.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
43. What does the new operator do in the following statement?
double* num = new double[10];

A) It allocates an array of size 10, and yields a pointer to the starting element.
B) It allocates enough memory for a double value and initializes it with 10
C) It allocates enough memory for 10 pointers.
D) This is not a legal statement, it will generate a compiler error.

Ans: A
Title: What does new operator do in this statement?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.4

44. Which of the following operators is used to reclaim memory in the heap?

A) erase
B) recycle
C) reclaim
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) delete

Ans: D
Title: Which operator is used to reclaim memory in the heap?
Difficulty: Easy
Section Ref: 7.4

45. What is the legal statement to reclaim the memory allocated below?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int* num = new int;
*num = 10;

A) delete num;
B) delete[] num;
C) delete num[];
D) delete *num;

Ans: A
Title: Which statement reclaims the memory allocated below?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.4

45. What is wrong with the following code snippet?
int main()
{
double* deleted;
*deleted = 10;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "*deleted is now " << *deleted << endl;
}

A) There is a double pointer being used in the program.
B) There is a deleted pointer being used in the program.
C) There is an uninitialized pointer being used in the program.
D) There is a compiler error in the program.

Ans: C
Title: What is wrong with snippet (with pointer error)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.4

46. Consider the following code snippet:
int* num = new int;
*num = 10;
cout << num << endl;
delete num;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
*num = *num * 2;
cout << num << endl;

Which of the following statements is correct?

A) There is no error in the code snippet.
B) The num pointer is being used after the memory it is pointing to has been deleted.
C) There are compilation errors.
D) The num pointer was never initialized.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: Which statement is correct (about snippet with new)?
Difficulty: Hard
Section Ref: 7.4

47. Consider the code snippet below
int important_calculation(int size)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int the_answer = 42;
int* ptr = new int[size];
ptr[0] = the_answer;
return the_answer;
}

Which of the following statements is true about the code snippet?

A) There is an uninitialized pointer that is used.
B) There is a new without a matching delete.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) There is memory that is never reclaimed.
D) Both b and c.

Ans: D
Title: Which statement is correct (about snippet with new)?
Difficulty: Easy
Section Ref: 7.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
48. What is wrong with the code snippet below?
void do_it()
{
int* num1 = new int[10];
int* num2 = new int[20];
num1[0] = 100;
num2[0] = num1[0];
num1 = num2;
// more important stuff here
delete[] num2;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) num2 cannot be assigned to num1
B) The memory that num2 points to originally is never released.
C) The memory that num1 points to originally is never released.
D) There is no problem with this code snippet.

Ans: C
Title: What is wrong with snippet (with new)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.4

49. Examine the following code snippet. Which statement best describes p_array?
int* p_array[10];

A) It is a pointer to an array of 10 integers.
B) It is a pointer to an integer initialized with 10.
C) It is an array of ten integer pointers.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) There is a compilation error.

Ans: C
Title: Which statement best describes (variable declared here)?
Difficulty: Medium
Section Ref: 7.5

50. Which of the following statements is the legal way of declaring a vector of pointers?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) vector marks[5];
B) vector* marks(5);
C) vector* marks(5);
D) vector marks(5);

Ans: D
Title: Which is the legal way of declaring a vector of pointers?
Difficulty: Medium
Section Ref: 7.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

51. What is true about the statement given below?
int* ptr_num;

A) ptr_num is an integer variable.
B) ptr_num contains the memory location of an integer variable.
C) ptr_num can store two memory addresses simultaneously.
D) ptr_num can also store a string value.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: What is true about (variable declaration)?
Difficulty: Easy
Section Ref: 7.1

52. Consider the code snippet below.
int num = 500;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int* ptr_num = &num;
Which of the following observations are true based on the code snippet?

A) ptr_num stores the value of num
B) ptr_num stores the address of num
C) &ptr_num gives the address of num
D) &ptr_num gives the value of num

Ans: B
Title: Which is true about snippet (with assignment to pointer)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.1

53. What is the output of the following code snippet?
int number = 0;
int* ptr_num = &number;
*ptr_num = 60;
number = 80;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << *ptr_num << endl;

A) 0
B) 60
C) 80
D) the address of number

Ans: C
Title: What is output of snippet (assigning values and addresses)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.1

54. What is the output of the following code snippet?
double num = 0.0;
double* ptr = &num;
num = 15.0;
*ptr = *ptr + 15.0;
cout << num << " " << *ptr << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) 15 15
B) 15 30
C) 30 15
D) 30 30

Ans: D
Title: What is output of snippet (dereferencing pointers)?
Difficulty: Medium
Section Ref: 7.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

55. What is the output of the following code snippet?
int* ptr_num;
*ptr_num = *ptr_num + 10;
cout << *ptr_num << endl;

A) There is no output due to compilation errors.
B) The address stored in ptr_num
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 10
D) The code snippet compiles but results in an unpredictable error when the code snippet is run because it uses an uninitialized pointer.

Ans: D
Title: What is the output of snippet (with pointer variable)?
Difficulty: Medium
Section Ref: 7.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
56. What is the output of the following code snippet?
int* speed = NULL;
cout << *speed << endl;

A) There is no output due to a compilation error.
B) 0
C) NULL
D) There are no compilation errors but when the code snippet is run, it results in an illegal data access error.

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the output of snippet (with NULL pointer)?
Difficulty: Medium
Section Ref: 7.1

57. What is the output of the following code snippet?
double* temperature = NULL;
cout << temperature << endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) There is no output due to a compilation error.
B) 0
C) “NULL”
D) There are no compilation errors but when the code snippet is run, it results in an illegal data access error.

Ans: B
Title: What is the output of snippet (with NULL pointer)?
Difficulty: Medium
Section Ref: 7.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

58. Which location of the array num does ptr point to right after you assign an array to a pointer variable, as shown in the following code snippet?
int num[5];
int* ptr = num;

A) num[0]
B) num[1]
C) num[5]
D) You cannot assign an array to a pointer.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: Which array location does ptr point to (after array assigned to pointer)?
Difficulty: Easy
Section Ref: 7.2

59. Given the following code snippet, what is true about the statement ptr_num++?
int num[5] = { 1, 2, 3, 4, 5 };
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int* ptr_num = num;
ptr_num++;

A) ptr_num now points to num[0];
B) ptr_num now points to num[1];
C) ptr_num++ results in a compilation error.
D) ptr_num++ results in a run-time error.

Ans: B
Title: What is true about ptr_num++ in snippet (that assigns array to ptr_num)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.2

60. What is the output of the following code snippet?
int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int* ptr = arr;
ptr = ptr + 5;
cout << *ptr << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) There is no output due to a compilation error.
B) 4
C) 5
D) 6

Ans: D
Title: What is output of snippet (that uses pointer arithmetic)?
Difficulty: Hard
Section Ref: 7.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

61. Consider the code snippet below.
int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Which of the following is the value of *(arr + 5)?

A) 4
B) 5
C) 6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 8

Ans: C
Title: What is output of snippet (that uses array/pointer duality)?
Difficulty: Medium
Section Ref: 7.2

62. Suppose that you declare an array int arr_num[10]. Assuming the function declaration statement given below, what would you use to pass the array to the given function?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int sum_arr(int arr_num[])

A) sum_arr(arr_num)
B) sum_arr(arr_num[0])
C) sum_arr(*arr_num)
D) sum_arr(&arr_num)

Ans: A
Title: What (syntax) would you use to pass an array to this function?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.2

63. A programmer writes the sum_num_array function, as shown in the following code snippet. The programmer was surprised to find incorrect output from the main program. What is wrong with the following code snippet?
int sum_num_array(int num_array[], int size)
{
int result = 0;
for (int i = 0; i < size; i = i + 2)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
result = result + num_array[i];
}
return result;
}
int main()
{
int sum_num_array(int num_array[], int size);
int num[6] = { 1, 2, 3, 4, 5, 6 };
int sum = sum_num_array(num, 8);
cout << "Sum: " << sum << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}

A) The sum_num_array function works only with an array with an even number of values.
B) It is not possible to pass an array as an argument to a function.
C) The main function passes an incorrect size for the num array.
D) The main function does not initialize the num array correctly before passing it to the sum_num_array function.

Ans: C
Title: What is wrong with this code (that passes an array to a function)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 7.2

64. Which of the following is true about the char_arr variable?
char char_arr[] = “Let Us C++!”;

A) char_arr is an array of size 10, and the last value in the array is “!”.
B) char_arr is an array of size 11, and the last value in the array is “!”.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) char_arr is an array of size 12, and the last value in the array is “”.
D) char_arr is an array of size 11, and the last value in the array is “”.

Ans: C
Title: Which is true about (char array initialized with literal string)?
Difficulty: Easy
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
65. What is the output of the following code snippet?
int main()
{
int i = 5;
char* name = “Philip Roger”;

cout << name[i] << endl;
return 0;
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) p
B) ip
C) Roger
D) The program does not compile due to a syntax error.

Ans: A
Title: What is output of snippet (with pointer to char array)?
Difficulty: Medium
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

66. What is the output of the following code snippet?
int age = 0;
string str_age = “45”;
age = atoi(str_age);
cout << age << endl;

A) 0
B) 45
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) There is no output due to a compilation error.
D) There is no output due to a run-time error.

Ans: C
Title: What is output of snippet (that uses atoi)?
Difficulty: Medium
Section Ref: 7.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
67. You have declared the following string variable: string name_manager = “Susan”; Which of the following statements is a legal assignment statement?

A) string* strp = name_manager.c_str();
B) string str = c_str(name_manager);
C) const char* cstr = name_manager.c_str();
D) const char* cstr = c_str(name_manager);

Ans: C
Title: Which is a legal assignment statement (using c_str())?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.3

68. Which of the following statement(s) represents a valid declaration of a C++ string variable?

A) string str_vowels = null;
B) string str_vowels = ”;
C) string str_vowels = “aeiou”;
D) string str_vowels = { ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ };
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: C
Title: Which is a valid declaration of a C++ string variable?
Difficulty: Medium
Section Ref: 7.3

69. How can you access the character ‘n’ in the following C++ string?
string student_name = “Susan”;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) char last = student_name[4];
B) char last = student_name[5];
C) char last = student_name.substr(5);
D) char last = student_name.substr(4, 5);

Ans: A
Title: How can you access the character ‘n’ in this C++ string?
Difficulty: Easy
Section Ref: 7.3
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

70. What does the new operator do in the following statement?
double* some_num = new double[20];

A) It allocates an array of size 20, and yields a pointer to the starting element.
B) It allocates enough memory for a double value and initializes it with 20.
C) It allocates enough memory for 20 pointers.
D) This is not a legal statement; it will generate a compiler error.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: What does new operator do in this statement?
Difficulty: Medium
Section Ref: 7.4

71. What is the legal statement to reclaim the memory allocated below?
int* some_num = new int;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
*some_num = 20;

A) delete some_num;
B) delete[] some_num;
C) delete some_num[];
D) delete *some_num;

Ans: A
Title: Which statement reclaims the memory allocated below?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.4

72. What is wrong with the following code snippet?
int main()
{
double* to_be_deleted;
*to_be_deleted = 25;
cout << "* to_be_deleted is now " << *to_be_deleted << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) There is a double pointer being used in the program.
B) There is a deleted pointer being used in the program.
C) There is an uninitialized pointer being used in the program.
D) There is a compiler error in the program.

Ans: C
Title: What is wrong with snippet (with pointer error)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.4

73. Consider the following code snippet.
int* age = new int;
*age = 20;
cout << age << endl;
delete age;
*age = *age * 3;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << age << endl;

Which of the following statements is correct?

A) There is no error in the code snippet.
B) The age pointer is being used after the memory it is pointing to has been deleted.
C) There are compilation errors.
D) The age pointer was never initialized.

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement is correct (about snippet with new)?
Difficulty: Hard
Section Ref: 7.4

74. What is wrong with the code snippet below?
void did_it()
{
int* number1 = new int[10];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int* number2 = new int[20];
number1[0] = 100;
number2[0] = number1[0];
number1 = number2;
// more important stuff here
delete[] number2;
}

A) number2 cannot be assigned to number1
B) The memory that number2 points to originally is never released.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) The memory that number1 points to originally is never released.
D) There is no problem with this code snippet.

Ans: C
Title: What is wrong with snippet (with new)?
Difficulty: Medium
Section Ref: 7.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
75. Examine the following code snippet. Which statement best describes num_array?
int* num_array[100];

A) It is a pointer to an array of 100 integers.
B) It is a pointer to an integer initialized with 100.
C) It is an array of 100 integer pointers.
D) There is a compilation error.

Ans: C
Title: Which statement best describes (variable declared here)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.5

76. Using pictures can help determine the structure of data and connections of data within a program. How are pointers usually represented in a diagram?
A) Data storage locations are represented as boxes; pointers are drawn as arrows with the tip pointing to the boxes
B) Data storage locations are represented as arrow; pointers are drawn as boxes.
C) Data storage locations and pointers are both drawn as arrows
D) Data storage locations and pointers are both drawn as boxes
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: How are pointers drawn in a diagram?
Difficulty: Easy
Section Ref: 7.6

77. Given the following code, describe the diagram that would represent the situation with the variables:
int A = 10;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int B = 42;
int* p;
int* q;
int* x;
p = &A;
q = &B;
x = p;
p = q;

A) Two boxes – one with 10, one with 42 – and three arrows which all point to 42
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Two boxes – one with 10, one with 42 – and two arrows pointing to 10 and one pointing to 42
C) Two boxes – one with 10, one with 42 – and one arrow pointing to 10 and two pointing to 42
D) Two boxes – one with 10, one with 42 – and three arrows which all point to 10

Ans: C
Title: Describe the picture that represents the variables
Difficulty: Medium
Section Ref: 7.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

78. Given the following code, describe how to draw the address &p as an arrow within the diagram that would represent the situation with these variables:
int A = 10;
int B = 42;
int* p;
int* q;
p = &A;
q = &B;
A) Two boxes, one with 10, one with 42; two arrows, one pointing to 10, one pointing to 42
B) Two boxes, one with 10, one with 42; three arrows, two pointing to 10, one pointing to 42
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) Three boxes, one with 10, one with 42, and one labeled p; three arrows, one pointing to 10, one pointing to 42, and one pointing to p
D) Three boxes, one with 10, one with 42, and one labeled p; two arrows, one pointing to 10, one pointing to 42

Ans: A
Title: Describe the picture that represents the variables
Difficulty: Medium
Section Ref: 7.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

79. Describe how the two arrays index and data are related to one another after the code snippet below executes:
int* index[5];
int data[10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0};
int i = 0;
int* p = &data[9];
for (int i = 0; i < 5; i++)
{
index[i] = p;
p–;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) The elements of data point to the elements of index as follows:
data[0] points to index[9]
data[1] points to index[8]
etc. for the first five elements of data
B) The elements of data point to the elements of index as follows:
data[0] points to index[0]
data[1] points to index[1]
etc. for the first five elements of data
C) The elements of index point to the elements of data as follows:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
index[0] points to data[0]
index[1] points to data[1]
etc. for all five elements of index
D) The elements of index point to the elements of data as follows:
index[0] points to data[9]
index[1] points to data[8]
etc. for all five elements of index

Ans: D
Title: Describe how the two arrays are related to each other after the code snippet executes
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 7.6

80. What is the output from the code snippet below?
int* index[5];
int data[10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0};
int i = 0;
int* p = &data[9];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i < 5; i++)
{
index[i] = p;
p–;
}
for (int i = 0; i < 5; i++)
{
cout << *index[i] << " ";
}
A) 4 8 1 3 5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 5 3 1 8 4
C) 0 6 2 3 9
D) 9 3 2 6 0

Ans: C
Title: What is the output from the code snippet involving two arrays and pointers?
Difficulty: Hard
Section Ref: 7.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

81. Describe how the two arrays index and data are related to one another after the code snippet below executes:
int* index[5];
int data[10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0};
int i = 0;
int* p = &data[0];
for (int i = 0; i < 5; i++)
{
index[i] = p;
p++;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) The elements of data point to the elements of index as follows:
data[0] points to index[9]
data[1] points to index[8]
etc. for the first five elements of data
B) The elements of data point to the elements of index as follows:
data[0] points to index[0]
data[1] points to index[1]
etc. for the first five elements of data
C) The elements of index point to the elements of data as follows:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
index[0] points to data[0]
index[1] points to data[1]
etc. for all five elements of index
D) The elements of index point to the elements of data as follows:
index[0] points to data[9]
index[1] points to data[8]
etc. for all five elements of index

Ans: C
Title: Describe how the two arrays are related to each other after the code snippet executes
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 7.6

82. What is the output from the code snippet below?
int* index[5];
int data[10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0};
int i = 0;
int* p = &data[0];
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i < 5; i++)
{
index[i] = p;
p++;
}
for (int i = 0; i < 5; i++)
{
cout << *index[i] << " ";
}
A) 4 8 1 3 5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 5 3 1 8 4
C) 0 6 2 3 9
D) 9 3 2 6 0

Ans: A
Title: Describe how the two arrays are related to each other after the code snippet executes
Difficulty: Hard
Section Ref: 7.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

83. What is the output from the code snippet below?
int* index[5];
int data[10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0};
int i = 0;
int* p = &data[5];
for (int i = 0; i < 5; i++)
{
index[i] = p;
p++;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
for (int i = 0; i < 5; i++)
{
cout << *index[i] << " ";
}
A) 4 8 1 3 5
B) 5 3 1 8 4
C) 0 6 2 3 9
D) 9 3 2 6 0

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: Describe how the two arrays are related to each other after the code snippet executes
Difficulty: Hard
Section Ref: 7.6

84. Given the following declaration of the variables p1 and p2, which code fragment prints “Hello” if the value of x in the variable p1 is larger than the value of x in the variable p2?
struct Point2D
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
double x;
double y;
};
Point2D p1;
Point2D p2;
A) if (p1.y > p2.y)
{
cout << "Hello";
}
B) if (p1.x > p2.x)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << "Hello";
}
C) if (x.p1 > x.p2)
{
cout << "Hello";
}
D) if (Point2D.x > Point2D.x)
{
cout << "Hello";
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

Ans: B
Title: Which code fragment using structs correctly generates the requested output?
Difficulty: Easy
Section Ref: 7.7

85. Given the following declaration of the variables p1 and p2, which code fragment prints “Maximum” if the value of x in the variable p1 is larger than the value of x in the variable p2?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
struct Point2D
{
double x;
double y;
};
Point2D *p1;
Point2D p2;
p1 = new Point2D;

A) if (p1.x > p2.x)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << "Maximum";
}
B) if (p1->x > p2->x)
{
cout << "Maximum";
}
C) if (p1->x > p2.x)
{
cout << "Maximum";
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
D) if (p1.x > p2->x)
{
cout << "Maximum";
}

Ans: C
Title: Which code fragment using structs correctly generates the requested output?
Difficulty: Easy
Section Ref: 7.7
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

86. Given the following definitions and declaration of the Triangle t, which code fragment prints the x-coordinate from vertex 2 of Triangle t?
struct Point2D
{
double x;
double y;
};
struct Triangle
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
Point2D *v1;
Point2D *v2;
Point2D *v3;
}
Triangle t;
t.v1 = new Point2D;
t.v2 = new Point2D;
t.v3 = new Point2D;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) cout << "Vertex 2, x value: " <x << endl;
B) cout << "Vertex 2, x value: " <v2->x << endl;
C) cout << "Vertex 2, x value: " <v2.x << endl;
D) cout << "Vertex 2, x value: " << t.v2.x << endl;

Ans: A
Title: Which code fragment using structs correctly generates the requested output?
Difficulty: Medium
Section Ref: 7.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

87. What value is stored in mytri.v1.x after the code below executes?
struct Point2D
{
double x;
double y;
};
struct Triangle
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Point2D v1;
Point2D v2;
Point2D v3;
};
void f(Triangle& t)
{
int temp = 12.5;
temp = t.v1.x;
t.v1.x = t.v1.y;
t.v1.y = temp;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
int main()
{
Triangle mytri;
mytri.v1.x = 1.0;
mytri.v1.y = 22.5;
f(mytri);
}

A) 1.0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 22.5
C) 12.5
D) 23.5

Ans: B
Title: What value is stored in the variable (struct) after the code snippet executes?
Difficulty: Medium
Section Ref: 7.7

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

88. What value is stored in mytri.v1.x after the code below executes?
struct Point2D
{
double x;
double y;
};
struct Triangle
{
Point2D v1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Point2D v2;
Point2D v3;
};
void f(Triangle t)
{
int temp = 12.5;
temp = t.v1.x;
t.v1.x = t.v1.y;
t.v1.y = temp;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main ()
{
Triangle mytri;
mytri.v1.x = 1.0;
mytri.v1.y = 22.5;
f(mytri);
}

A) 1.0
B) 22.5
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 12.5
D) 23.5
Ans: A
Title: What value is stored in the variable (struct) after the code snippet executes?
Difficulty: Medium
Section Ref: 7.7

89. What does the function f do?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
struct Point2D
{
double x;
double y;
};
struct Triangle
{
Point2D v1;
Point2D v2;
Point2D v3;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
};
void f(Triangle& t)
{
int temp = 12.5;
temp = t.v1.x;
t.v1.x = t.v1.y;
t.v1.y = temp;
}
int main ()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Triangle mytri;
mytri.v1.x = 1.0;
mytri.v1.y = 22.5;
f(mytri);
}

A) Swaps values of x and y in vertex 1 of an argument of type Triangle
B) Initializes value of x in vertex 1 of an argument of type Triangle
C) Sets all x,y values in all vertices of an argument of type Triangle
D) Swaps value of x in vertex 1 with value of x in vertex 2, for an argument of type Triangle
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: What does the function (with a struct argument) do?
Difficulty: Medium
Section Ref: 7.7

90. What is the output of the following code snippet?
void myfun(char *p)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << *p;
p++;
}

int main()
{
char myword[20] = “You had me at hello”;
for (int i = 0; i < 10; i++)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
myfun(&myword[i]);
}
A) You had
B) You had me
C) You had me at
D) You had me at hello

Ans: B
Title: What is the output of the following code snippet?
Difficulty: Hard
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 7.1

91. What is the problem with line 3 of the code below?
1 void myfun(char* p)
2 {
3 *p++;
4 cout << *p;
5 }
6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
7 int main()
8 {
9 char myword[20] = “YouHadMeAtHello”;
10 for (int i = 0; i < 10; i++)
11 {
12 myfun(&myword[i]);
13 }
14 cout << endl;
15}
A) Cannot increment a pointer variable
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Cannot change a parameter variable
C) May work but confusing: depends on knowing precedence between the * and ++ operators
D) There is no problem

Ans: C
Title: What is the problem with the given line of code?
Difficulty: Hard
Section Ref: 7.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

92. What is the output of the following code snippet?
char* myfun()
{
char mychar = ‘A’;
char* p;

p = &mychar;
return p;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

int main()
{
cout << *(myfun()) << endl;
return 0;
}

A) A
B) a
C) Unpredictable
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Will not compile

Ans: C
Title: What is the output of the code snippet, which returns a pointer from a function?
Difficulty: Hard
Section Ref: 7.2

93. What is the output of the following code snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
char* myfun()
{
char mychar = ‘A’;
char* p;

p = new char;
*p = mychar;
return p;
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
cout << *(myfun()) << endl;
return 0;
}

A) A
B) a
C) unpredictable
D) will not compile
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: What is the output of the following code snippet (function returning pointer)
Difficulty: Hard
Section Ref: 7.2

94. What is the output of the following code snippet?
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
char mychar = ‘W’;
char *p;
{
char mychar = ‘X’;
p = &mychar;
}
cout << mychar << *p << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) WW
B) WX
C) XX
D) Unpredictable result

Ans: D
Title: What is the output of the code snippet (pointers to block variables)?
Difficulty: Medium
Section Ref: 7.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

95. In order to convert a string containing digits (such as converting the string “1249” to the integer 1249), which of the following expressions can be used? Assume the following variables have been defined:
string mystring = “1249”;
int myInt;
A) myint = mystring.convert();
B) myint = atoi(mystring.c_str());
C) myint = mystring.c_str();
D) myint = mystring.atoi();
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: How do you convert a string containing digits to an integer?
Difficulty: Medium
Section Ref: 7.3

96. What is the output of the following code snippet?
void myfun(char* p)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
*p = toupper(*p);
}

int main()
{
char myword[20] = “YouHadMeAtHello”;
for (int i = 0; i < 10; i++)
{
myfun(&myword[i]);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
cout << myword << endl;
return 0;
}
A) YouHadMeAt
B) YOUHADMEAT
C) YouHadMeAtHello
D) YOUHADMEATHello

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the output of the code snippet (function using pointers and toupper() function)
Difficulty:
Section Ref: 7.3

97. What is wrong with the following code snippet?
void myfun(char* p)
{
*p = toupper(*p);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

int main()
{
string myword = “YouHadMeAtHello”;
for (int i = 0; i<10; i++)
{
myfun(myword[i]);
}
cout << myword << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return 0;
}

A) Must use c_str() to access individual characters of the string variable myword
B) Array indices are out of bounds
C) Must use atoi() to convert integers to characters
D) The toupper() function cannot be applied to a single character

Ans: A
Title: What is wrong with the code snippet (accessing individual characters of a string)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 7.3

98. The code snippet below creates what kind of a problem?
int main()
{
string* myword[20];
for (int i = 0; i < 14; i++)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
myword[i] = new string(“YouHadMeAtHello”);
}
cout << *myword[15] << endl;
return 0;
}

A) Off by one error
B) Null pointer dereference
C) Memory leak
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Array index out of bounds

Ans: B
Title: What problem is created by the code snippet?
Difficulty: Medium
Section Ref: 7.4

99. The code snippet below creates what kind of a problem?
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
string* myword[20];
for (int i = 0; i < 10; i++)
{
myword[i] = new string(“YouHadMeAtHello”);
}
cout << *myword[15] << endl;
return 0;
}

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Off by one error
B) Invalid pointer dereference
C) Memory leak
D) Array index out of bounds

Ans: B
Title: What problem is created by the code snippet?
Difficulty: Medium
Section Ref: 7.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

100. The code snippet below creates what kind of a problem?
int main()
{
string* myword;
for (int i = 0; i < 14; i++)
{
myword = new string(“YouHadMeAtHello”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
cout << *myword << endl;
return 0;
}

A) Off by one error
B) Null pointer dereference
C) Memory leak
D) Array index out of bounds

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Title: What problem is created by the code snippet?
Difficulty: Medium
Section Ref: 7.4

1. Which of the following streams is used to read as well as write disk files?

A) ifstream
B) ofstream
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) fstream
D) iofstream

Ans: C
Title: Which stream is used to read as well as write disk files?
Difficulty: Easy
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
2. Which of the following options is NOT used for working with file streams?

A) ifstream
B) ofstream
C) fstream
D) iofstream

Ans: D
Title: Which is NOT used for working with file streams?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.1

3. In the following code snippet, which line can cause a compilation error, assuming the code includes all required header files and namespace statements?

1. ifstream infile;
2. infile.open(“sample.txt”);
3. infile << "This is an inserted text!" << endl << "This is also an inserted text!!!" << endl;
4. infile.close();
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Line 1
B) Line 2
C) Line 3
D) Line 4

Ans: C
Title: Which line can cause a compilation error (in snippet writing to ifstream)?
Difficulty: Medium
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

4. Assuming that “in_file” is an ifstream object, what is the correct way of opening a file “File.txt” for reading?

A) in_file(“File.txt”)
B) in_file.open(“File.txt”)
C) in_file(File.txt)
D) in_file.open(File.txt)

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: What is correct code for opening a file “File.txt” for reading?
Difficulty: Medium
Section Ref: 8.1

5. Which of the following headers is required for reading from and writing to disk files?

A) #include
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) #include
C) #include
D) #include

Ans: D
Title: Which header is required for reading from/writing to disk files?
Difficulty: Medium
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

6. Consider the following code snippet and assume that the file “File.txt” does not exist. Which of the following options is true?

#include
int main()
{
char ch;
ifstream in_file;
in_file.open(“File.txt”);
if (in_file.fail())
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << "File not found!" << endl;
return 1;
}
while (in_file.get(ch))
{
cout << ch;
}
cout << "The file has been read!" << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) There is no output because the file does not exist.
B) The program prints 1.
C) The program prints The file has been read!
D) The program prints File not found!

Ans: D
Title: Which is true about snippet (when file to be read does not exist)?
Difficulty: Hard
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.1

7. Which of the following options is the correct way to call the open function on an ifstream object named ifstr?

A) ifstr.open()
B) ifstr.open(“data.txt”)
C) ifstr.open(“data.txt”, “read”)
D) ifstr.open(“data”, “.txt”)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: Which is correct way to call open on ifstream object named ifstr?
Difficulty: Easy
Section Ref: 8.1

8. Which of the following options represents the correct syntax to open a file whose name is contained in the variable filename?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "Please enter the file name:";
string filename;
cin >> filename;
ifstream in_file;

A) in_file.open(filename.c_str());
B) in_file.open(filename);
C) in_file.open(c_str(filename));
D) in_file.open(“filename”);

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: Which is correct syntax to open file whose name is contained in variable filename?
Difficulty: Easy
Section Ref: 8.1

9. Consider the following code snippet:

1. int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
2. {
3. char ch;
4. ifstream in_file;
5. in_file.open(“C:names.txt”);
6. while (in_file.get(ch))
7. {
8. cout << ch;
9. }
return 0;
10. }
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Which of the following statements describes the problem with this code snippet?

A) The variable in_file is never assigned a value.
B) Line 5 does not open the file C:names.txt.
C) There is a syntax error in line 6.
D) The program contains an infinite loop.

Ans: B
Title: Which is problem with snippet (with file name as literal string)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 8.1

11. The File.txt file contains the statement This is a file. What is the output of the following code snippet?

int main()
{

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
ifstream in_file;
in_file.open(“File.txt”);

string str1, str2;
getline(in_file, str1);
getline(in_file, str2);

cout << str1 << endl;
cout << str2 << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) This is a file
This is a file
B) This is a file

C)
This is a file
D) There is no output because the code snippet does not compile.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: What is output of snippet (using getline to read from file)?
Difficulty: Hard
Section Ref: 8.1

12. Assuming that in_file is an ifstream object, which of the following statements can be used to read a name from a data file?

A) in_file >> name;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) in_file.get_line(name);
C) in_file.get(name);
D) in_file << name;

Ans: A
Title: Which can be used to read a name from a data file (ifstream)?
Difficulty: Easy
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

13. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes.
I. Declare an ifstream variable in_file
II. Replace all occurrences of cin with in_file
III. Replace all occurrences of >> and get_line with the appropriate operations for ifstream objects
What changes do you need to make?

A) I and II
B) I and III
C) II and III
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) I, II, and III

Ans: A
Title: What changes do you need to make (to read from file instead of from cin)?
Difficulty: Easy
Section Ref: 8.2

14. Which of the following options tests for failure after opening a file into an ifstream object?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) if (in_file.fail()) { report_error(); }
B) if (!in_file.fail()) { report_error(); }
C) if (in_file.is_open()) { report_error(); }
D) if (in_file) { report_error(); }

Ans: A
Title: TB Which tests for the failure after opening a file into an ifstream object?
Difficulty: Medium
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

15. Consider the following code snippet:

string name;
int scores;
ifstream in_file;
in_file.open(“Results.txt”);
Assume that the file “Results.txt” contains the last names and scores of students, for example,
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Smith 94
Jones 81

What is the legal way of reading a student’s name and the student’s scores in the “Results.txt” file?

A) in_file >> name >> scores;
B) in_file << name << scores;
C) get_line(in_file, name); in_file >> scores;
D) get_line(in_file, name); get_line(in_file, scores);

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What is legal way of reading a student’s name/scores in the “Results.txt” file?
Difficulty: Medium
Section Ref: 8.2

16. Assume that the file “Results.txt” contains the following data:
Peter 90
John 80
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Mary Lou 100
Robert 40
Simon 50
Samuel 30
What is the output of the following code snippet?
int main()
{
string name;
int total = 0;
double count_pass = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
double average = 0;
int scores;
ifstream in_file;
in_file.open(“Results.txt”);
while (in_file >> name >> scores)
{
if (scores >= 50)
{
total = total + scores;
count_pass++;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
}
average = total / count_pass;
cout << "The average of passed students: " << average << endl;
return 0;
}

A) The average of passed students: 0
B) The average of passed students: 90
C) The average of passed students: 80
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) There is no output due to compilation errors.

Ans: C
Title: What is output of snippet (that reads data with >> )?
Difficulty: Hard
Section Ref: 8.2

17. Which of the following object types is used to open a file for writing?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) ifstream
B) fostream
C) ofstream
D) stream

Ans: C
Title: Which object type is used to open a file for writing?
Difficulty: Easy
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

18. Assuming that out_file is an ofstream variable, what is the legal way of writing the string name to a file?

A) out_file << name;
B) out_file.write(name);
C) out_file >> name;
D) write_line(out_file, name);

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What is legal way of writing the string name to a file (ofstream variable)?
Difficulty: Easy
Section Ref: 8.1

19. Consider the following code snippet:
ofstream out_file;
out_file.open(“Scores.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
out_file << "Peter" << " " << 20 << endl;
out_file << "John" << " " << 50 << endl;
Assuming that the file “Scores.txt” does not exist, which of the following statements is true about the above code snippet?

A) The code snippet causes an error due to the missing file.
B) The code snippet creates a new file “Scores.txt” with no data in it.
C) The code snippet causes an error because both string and integer cannot be written in the same line of text.
D) The code snippet creates a new file “Scores.txt” and writes the data to it.

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: If file does not exist, which is true about snippet (that writes to it)?
Difficulty: Medium
Section Ref: 8.1

20. Which of the following options represents a legal way of writing to a file on the basis of the code snippet provided?
int main()
{
ofstream out_file;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
out_file.open(“Scores.txt”);
// statement to write into the file
return 0;
}

A) out_file >> “Peter” >> ” ” < 20 < endl;
B) out_file << "Peter" << " " << 20 << endl;
C) out_file.write_line(“Peter”); out_file << 20 << endl;
D) out_file.write_line(“Peter”); out_file >> 20 >> endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: Which is legal way of writing to this file (ofstream)?
Difficulty: Medium
Section Ref: 8.1

21. Assuming that the “In.txt” file contains the text “A quick brown fox jumps over the lazy dog!” what are the contents of “Out.txt” after executing the following code snippet?
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
ifstream in_file;
ofstream out_file;
in_file.open(“In.txt”);
out_file.open(“Out.txt”);
char ch;
int num = 0;
while (in_file.get(ch))
{
if (num % 5 == 0)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
out_file << ch;
}
num++;
}
return 0;
}

A) A quick brown fox jumps over the lazy dog
B) A qui
C) Acoomvhzg
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) jumps!

Ans: C
Title: Assuming that “In.txt” contains …, what are contents of “Out.txt” after snippet?
Difficulty: Hard
Section Ref: 8.1

22. What is the correct way to pass an fstream object as a parameter to a function?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) As a value parameter.
B) As a reference parameter.
C) Cast as an ofstream object.
D) Cast as an ifstream object.

Ans: B
Title: What is correct way to pass an fstream object as a parameter to a function?
Difficulty: Easy
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

23. Which of the following statements is true about the parameters in the given code snippet?
void copy_file(… in_file, … out_file)
{
char ch;
while (in_file.get(ch))
{
out_file << ch;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
}

A) The parameters to the function must be references: void copy_file(ifstream& in_file, ofstream& out_file)
B) The parameters to the function must be pointers: void copy_file(ifstream* in_file, ofstream* out_file)
C) The parameters to the function must be of the type fstream: void copy_file(fstream in_file, fstream out_file)
D) The parameters to the function must be of type istream and ostream: void copy_file(istream in_file, ostream out_file)

Ans: A
Title: Which is true about the (stream) parameters in snippet?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 8.1

24. What is wrong with the following function definition?
void show_file(ifstream infile)
{
char ch;
while (infile.get(ch))
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
cout << ch;
}
}

A) The function does not read an end of line character to terminate the while loop.
B) The output from the function does not display all of the characters in the file.
C) The function must use a pointer to the ifstream parameter.
D) The function must use a reference to the ifstream parameter.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is wrong with function definition (with stream parameter)?
Difficulty: Medium
Section Ref: 8.1

25. Which of the following options is used to skip white space in a string while reading a file?

A) >> operator
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) get() function
C) << operator
D) unget() function

Ans: A
Title: Which is used to skip white space in a string while reading a file?
Difficulty: Easy
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

26. Consider the following code snippet:
#include
#include
int main()
{
char ch;
int n;
ifstream in_file;
in_file.open(“c:\File.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (in_file.get(ch))
{
if (isdigit(ch))
{
in_file.unget();
in_file >> n;
cout << n;
}
}
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

What is the output of the program if File.txt contains the text “Four and 20 blackbirds!”?

A) Four and 20 blackbirds!
B) 20
C) Four 20
D) 20 blackbirds!

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the output of program if (input file contains) “Four and 20 blackbirds!”?
Difficulty: Medium
Section Ref: 8.2

27. The given function is supposed to read an integer from a file and return the value of that integer. However, the integer that is read and returned does not include the first digit. What modification should be made to the following function to include the first digit in the returned integer?
int read_int(ifstream& infile)
{
int int_value = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
bool not_found = true;
char ch;
while (infile.get(ch) && not_found)
{
if (isdigit(ch))
{
infile >> int_value;
not_found = false;
}
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
return int_value;
}

A) The statement infile.unget(); should be placed immediately after the statement that reads the integer from the file.
B) The statement infile.unget(); should be placed immediately before the statement that reads the integer from the file.
C) not_found should be replaced by found. The statement infile.replace(); should be placed immediately before the statement that reads the integer from the file.
D) true and false should be switched.

Ans: B
Title: What modification should be made to function (that tests input)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 8.2

28. Assuming that the “Data.txt” file contains the following lines of text, what is the output on executing the given code snippet?
Peter 78
Albert 89
Susan 97
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
string str = “Hello World”;
string line;
int count = 0;
ifstream infile;
infile.open(“Data.txt”);
while(getline(infile, line))
{
count++;
str = line;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
cout << count << " " << str << " " << line << endl;
return 0;
}

A) 3 Susan 97 Hello World
B) 3 Hello World
C) 3 Susan 97
D) 3 Susan 97 Susan 97

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is the output of program (using getline with given input file)?
Difficulty: Medium
Section Ref: 8.2.3

28. Suppose you want to print minutes so that they have a leading zero if they are less than 10, for example 03. Which manipulator do you use?

A) left
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) fixed
C) setprecision
D) setfill

Ans: D
Title: Which manipulator do you use to print minutes with a leading zero?
Difficulty: Easy
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

29. What is the output of the following code snippet?
cout << setw(2) << setfill('0') << 9;

A) 9
B) 09
C) 009
D) 209

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is output of snippet (with manipulators)?
Difficulty: Easy
Section Ref: 8.3

30. Which of the following statements displays 123 as 00123?

A) cout << setw(5) << 123;
B) cout << left << setw(5) << 123;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) cout << setw(5) << setfill('0') << 123;
D) None of the options displays the required output.

Ans: C
Title: Which statement displays 123 as 00123?
Difficulty: Medium
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
31. Which of the following statements displays 123.567 as 123.57?

A) cout << setprecision(2) << 123.567;
B) cout << fixed << setprecision(2) << 123.567;
C) cout << setw(5) << 123.567;
D) None of the options displays the required output.

Ans: B
Title: Which statement displays 123.567 as 123.57?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.3

32. Which of the options will provide the following output?
00123
123

A) cout << setw(5) << setfill('0') << 123 << endl << left << 123;
B) cout << setw(5) << 123 << endl << right << 123;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) cout << setw(5) << setfill('0') << 123 << setw(5) << 123;
D) None of the options displays the required output.

Ans: A
Title: Which statement will display this (formatted) output?
Difficulty: Medium
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
33. What are the contents of the “Output.txt” file when you execute the following code snippet?
int main()
{
double salary = 123.4567;
ofstream out_file;
out_file.open(“Output.txt”);
outfile << left << setw(18) << salary << endl;
outfile << setfill('0') << setw(18) << salary << endl;
outfile << setprecision(18) << salary << endl;
return 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}

A) 123.457
00000000000123.457
123.456699999999999
B) 123.457
123.45700000000000
123.4567
C) 123.457
00000000000123.457
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
123.456699999999998
D) 123.457
00000000000123.457
123.457

Ans: B
Title: What are contents of “Output.txt” after snippet (with setw, setfill, setprecision)?
Difficulty: Hard
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

34. Which of the following statements is true about string streams?

A) String streams can read numbers that are contained within strings.
B) String streams can convert numbers to strings.
C) String streams use >> and << operators to perform read and write operations.
D) All of the listed items.

Ans: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which is true about string streams?
Difficulty: Easy
Section Ref: 8.4

35. What is the output of the following code snippet?
ostringstream strm;
strm << fixed << setprecision(3) << 100.0 / 3;
cout << strm.str() << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) 33.333
B) 33.3
C) There is no output because string streams don’t display output in the console window.
D) There is no output because the code does not compile.

Ans: A
Title: What is output of snippet (with fixed, setprecision)?
Difficulty: Easy
Section Ref: 8.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

36. Which of the following code snippets converts the integer n to a string s?

A) istringstream strm; string s; strm.str(n); str >> s;
B) ostringstream strm; string s; strm.str(n); str >> s;
C) istringstream strm; string s; strm << n; s = strm.str();
D) ostringstream strm; string s; strm << n; s = strm.str();

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: Which snippet converts the integer n to a string s?
Difficulty: Medium
Section Ref: 8.4

37. Given the following code snippet, what is the value of the variable day?
istringstream strm(“16 Jan 1981”);
int day = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
string month;
strm >> day >> month;

A) 0
B) 16
C) 1981
D) No value because the code snippet cannot compile due to errors.

Ans: B
Title: What is value of variable after snippet (that reads from string stream with >>)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 8.4

38. Which of the following options is true when you run the given code snippet?
int num1 = 0;
int num2 = 0;
string str1;
istringstream strm(“16 Feb 1982”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
strm >> num1 >> str1 >> num2;

A) num1 is 16
B) num2 is 16
C) num2 is 0
D) str1 is “1982”

Ans: A
Title: Which is true after snippet (that reads from string stream with >>)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.4

40. Which of the following code snippets correctly extracts only the dollar value from the string stream istringstream that is declared as follows:
char ch;
char ch2;
double d;
double d2;
istringstream strm(“$13.35”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) strm >> ch >> d >> ch2 >> d2;
B) strm << ch << d << ch2 << d2;
C) strm >> ch >> d;
D) strm << ch << d;

Ans: C
Title: Which snippet correctly extracts the dollar value from this string stream?
Difficulty: Medium
Section Ref: 8.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

41. To receive command line arguments at run-time, which of the following options represents the correct way to define the main function?

A) int main(int argc, char* argv[])
B) int main(int argc, char argv[])
C) int main(int argc[], char* argv)
D) int main(int* argc, char argv)

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: Which is correct way to define main to receive command line arguments?
Difficulty: Easy
Section Ref: 8.5

42. Which of the following statements is true about the command line arguments in a C++ program?

I. The first argument is the name of the program.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
II. The command line arguments are passed to the main function in an array.
III. The main function is defined as: int main(int argc, char* argv[]).

A) I only
B) II only
C) I and III only
D) I, II, and III.

Ans: D
Title: Which is true about command line arguments?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 8.5

43. Which of the following options represents the legal definition of the main() function so it can receive command line arguments?

A) int main(char argv[], int argc)
B) int main(int argc, char* argv[])
C) int main(char* argc, int argv[])
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) int main(int argv[], char* argc)

Ans: B
Title: Which legally defines the main() function to receive command line arguments?
Difficulty: Medium
Section Ref: 8.5

A) Assume that the main function definition of a C++ program ABC.cpp is int main(int argc, char* argv[]). If the ABC program is run with the following command, which of the options is true?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
ABC Alex Brendon Chris Roger 32 33 44 78

A) argc = 8 and argv[0] = “Alex”
B) argc = 8 and argv[0] = “ABC”
C) argc = 9 and argv[0] = “Alex”
D) argc = 9 and argv[0] = “ABC”

Ans: D
Title: Which is true when this program is run with these command line arguments?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.5

45. Consider the following code snippet:
int main(int argc, char* argv[])
{
for (int i = 0; i < argc; i++)
{
cout << "Argument " << i + 1 << ":" << argv[i] << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
return 0;
}
What is the output if the program is saved as ABC.cpp and run as ABC A B C?

A) Argument 1: ABC
Argument 2: A
Argument 3: B
Argument 4: C
B) Argument 2: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Argument 3: C
C) Argument 1: A
Argument 2: B
D) There is no output because of a bounds error.

Ans: A
Title: What (are arguments) if program is run as ABC A B C?
Difficulty: Medium
Section Ref: 8.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

46. Consider the following code snippet:
int main(int argc, char* argv[])
{
ifstream in_file;
ofstream out_file;
in_file.open(argv[1]);
out_file.open(argv[2]);
char ch;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (in_file.get(ch))
{
out_file << ch;
}
return 0;
}
Assuming that the file is saved as copy.cpp and there is data in the file in.dat, which of the following is a valid command to run this code snippet?

A) copy out.dat
B) copy in.dat
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) copy in.dat out.dat
D) copy out.dat in.dat

Ans: C
Title: Which is valid way to invoke this snippet (with command line arguments)?
Difficulty: Hard
Section Ref: 8.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
47. Reading one item after another from a file is called ____ access.

A) binary
B) random
C) sequential
D) None of the listed items

Ans: C
Title: Reading one item after another from a file is called ____ access.
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.6

49. Which of the following function calls can be used to get the current position for writing to a random access file?

A) strm.seekg(position)
B) strm.seekp(position)
C) strm.tellp(position)
D) strm.tellp()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: D
Title: Which function call gets the current position for writing to a random access file?
Difficulty: Medium
Section Ref: 8.6

50. Considering that you want to open a binary file for reading and writing, which of the following commands should you use?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) strm.open(filename, ios::in | ios::out | ios::binary);
B) strm.open(filename);
C) strm.open(filenameios::binary);
D) strm.open(filename, ios::in | ios::out);

Ans: A
Title: Which command should you use to open a binary file for reading and writing?
Difficulty: Medium
Section Ref: 8.6

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

51. Which of the following statements is true about the given code snippet?
fstream stm;
int offset = 16;
stm.open(“File.bin”, ios::in | ios::out | ios::binary);
stm.seekp(offset);
stm.seekg(offset + 8);
stm.put(‘A’);
stm.put(‘B’);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
char ch = stm.get();

A) The characters “A” and “B” are written into File.bin at locations 16 and 17.
B) The characters “A” and “B” are written into File.bin at locations 24 and 25.
C) The variable ch stores the character read from location 16 in File.bin.
D) The variable ch stores the character read from location 17 in File.bin.

Ans: A
Title: Which is true about snippet (using seekp, seekg, put, get)?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.6

52. For which purpose can you use the following function?
double mystery(fstream& stream, int offset)
{
stream.seekg(offset);
int result = 0;
for (int i = 0; i < 4; i++)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
result = result + stream.get();
}
return result / 4.0;
}

A) To calculate the average of four consecutive bytes read at the offset position in a file
B) To calculate and return an integer from the 4 bytes at the offset position in a file
C) To convert the value of the offset parameter to binary
D) None of the listed items
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: For what can you use this function (that reads bytes)?
Difficulty: Hard
Section Ref: 8.6

53. In the following code snippet, assuming the proper headers have been included, which line can cause a compilation error?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
1. ofstream outfile;
2. outfile.open(“My.txt”);
3. outfile >> “This text is to be inserted!” >> endl >> “This is also to be inserted!!!” >> endl;
4. outfile.close();

A) Line 1
B) Line 2
C) Line 3
D) Line 4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Title: Which line can cause a compilation error (in snippet reading from ofstream)?
Difficulty: Medium
Section Ref: 8.1

54. Assuming that “out_file” is an ofstream object, what is the correct way of opening a file “Employees.txt” for writing?

A) out_file(“Employees.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) out_file.open(“Employees.txt”);
C) out_file(Employees.txt);
D) out_Employees.open(Employees.txt);

Ans: B
Title: What is correct code for opening a file “Employees.txt” for writing?
Difficulty: Medium
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

55. Consider the following code snippet and assume that the file “Employees.txt” does not exist. Which of the following options is true?
#include
int main()
{
char ch;
ifstream read_file;
read_file.open(“Employees.txt”);
if (read_file.fail())
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << "The File could not be read!" << endl;
return 1;
}
while (read_file.get(ch))
{
cout << ch;
}
cout << "The File could be read!" << endl;
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) There is no output because the file does not exist.
B) The program prints the data in the file.
C) The program prints The File could be read!
D) The program prints The File could not be read!

Ans: D
Title: Which is true about snippet (when file to be read does not exist)?
Difficulty: Hard
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

56. Which of the following is the correct way to call the open function on an ofstream object called writestr?
A) writestr.open()
B) writestr.open(“File.txt”)
C) writestr.open(“File.txt”, “write”)
D) writestr.open(“File”, “.txt”)

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which is correct way to call open on ofstream object named writestr?
Difficulty: Easy
Section Ref: 8.1

57. Which of the following options represents the correct syntax snippet to open a file whose name is contained in the variable file_to_open?
cout << "Please enter the file name:" << endl;
string file_to_open;
cin >> file_to_open;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
ifstream in_file;

A) in_file.open(file_to_open.c_str());
B) in_file.open(file_to_open);
C) in_file.open(c_str(file_to_open));
D) in_file.open(“file_to_open”);

Ans: A
Title: Which is correct syntax to open file whose name is contained in variable file_to_open?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.1

58. Consider the following code snippet:
1. int main()
2. {
3. char rd;
4. ifstream read_file;
5. read_file.open(“C:network.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
6. while (read_file.get(rd))
7. {
8. cout << rd << endl;
9. }
10. return 0;
11. }

Which of the following statements describes the problem with this code snippet?

A) The variable read_file is never assigned a value.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) Line 5 does not open the file C:network.txt.
C) There is a syntax error in line 6.
D) The program contains an infinite loop.

Ans: B
Title: Which is problem with snippet (with file name as literal string)?
Difficulty: Medium
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

59. The Info.txt file contains the statement ‘This is a file which stores some information.’ What is the output of the following code snippet?
int main()
{
ifstream read_file;
read_file.open(“Info.txt”);

string line1;
string line2;
getline(read_file, line1);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
getline(read_file, line2);

cout << line1 << endl;
cout << line2 << endl;
return 0;
}

A) This is a file which stores some information
This is a file which stores some information
B) This is a file which stores some information
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

C)

This is a file which stores some information
D) There is no output because the code snippet does not compile.

Ans: B
Title: What is output of snippet (using getline to read from file)?
Difficulty: Hard
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

60. Assuming that out_file is an ofstream object, which of the following statements can be used to write a name to a data file?

A) out_file << name;
B) out_file.put_line(name);
C) out_file.put(name);
D) out_file >> name;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: Which can be used to write a name to a data file?
Difficulty: Easy
Section Ref: 8.1

61. Suppose you wrote a program that writes data using cout. You are now required to implement it so that you can write data to a file. You are considering the following changes.
I. Declare an ofstream variable out_file
II. Replace all occurrences of cout with out_file
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
III. Replace all occurrences of << and put_line with the appropriate operations for ofstream objects
What changes do you need to make?

A) I and II
B) I and III
C) II and III
D) I, II, and III

Ans: A
Title: What changes do you need to make (to write to file instead of to cout)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 8.1

62. Consider the following code snippet:
string name;
int payments;
ifstream read_file;
read_file.open(“Payroll.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Assume that the file “Payroll.txt” contains the last names and payments of students, for example,
Roger 155
Michelle 125

What is the legal way of reading a student’s name and the student’s payments in the “Payroll.txt” file?

A) read_file >> name >> payments;
B) read_file << name << payments;
C) get_line(read_file, name); read_file >> payments;
D) get_line(read_file, name); get_line(read_file, payments);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: What is legal way of reading a student’s name/payments in the “Payroll.txt” file?
Difficulty: Medium
Section Ref: 8.1
Title: Clone of Q14

63. Assume that the file “Payroll.txt” contains the following data:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Peter 90000
John 90000
Mary Lou 120000
Robert 150000
Simon 150000
What does the following program do?
int main()
{
string name;
double total = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int count = 0;
double average = 0;
double payments;
ifstream read_file;
read_file.open(“Payroll.txt”);
while (read_file >> name >> payments)
{
total = total + payments;
count ++;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
average = total / count;
cout << "Average: " << average << endl;
return 0;
}

A) It displays Average: 0.
B) It displays Average: 100000.
C) It displays Average: 90000.
D) It has a “divide by zero” error.

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: C
Title: What is output of snippet (that reads data with >> )?
Difficulty: Hard
Section Ref: 8.1

64. Assuming that read_file is an ifstream variable, what is the legal way of reading a string name from a file?

A) read_file >> name;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) read_file.read(name);
C) read_file << name;
D) read_line(read_file, name);

Ans: A
Title: What is legal way of reading the string name from a file (ifstream variable)?
Difficulty: Easy
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

65. Consider the following code snippet:
ifstream read_file;
string name = “”;
int score = 0;
read_file.open(“Scores.txt”);
read_file >> name >> score;
read_file >> name >> score;
Assuming that the file “Scores.txt” does not exist, which of the following statements is true about the above code snippet?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) The code snippet runs without reporting any errors, but never assigns a new value to the name or score variables.
B) The code snippet creates a new file “Scores.txt” with no data in it.
C) The code snippet creates a new file “Scores.txt” with junk data in it.
D) The code snippet causes an error because both string and integer cannot be read from the same line of text.

Ans: A
Title: If file does not exist, which is true about snippet (that reads from it)?
Difficulty: Medium
Section Ref: 8.1

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

66. Which of the following options represents a legal way of writing to a file on the basis of the code snippet provided?
int main()
{
ofstream write_file;
write_file.open(“Payroll.txt”);
// statement to write into the file
return 0;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) write_file >> “John” >> ” ” < 20000 < endl;
B) write_file << "John" << " " << 20000 << endl;
C) write_file.write_line(“John”); write_file << 20000 << endl;
D) write_file.write_line(“John”); write_file >> 20000 >> endl;

Ans: B
Title: Which is legal way of writing to this file?
Difficulty: Medium
Section Ref: 8.1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

67. Which of the following statements is true about the parameters in the given code snippet?
void lineno_file(… read_file, … write_file)
{
char ch;
int cnt_line = 0;
while (read_file.get(ch))
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cnt_line++;
write_file << cnt_line << " – " << ch;
}
}

A) The parameters to the function must be references: void lineno_file(ifstream& read_file, ofstream& write_file)
B) The parameters to the function must be pointers: void lineno_file(ifstream* read_file, ofstream* write_file)
C) The parameters to the function must be of the type fstream: void lineno_file(fstream read_file, fstream write_file)
D) The parameters to the function must be of type istream and ostream: void lineno_file(istream read_file, ostream write_file)

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: Which is true about the parameters in snippet?
Difficulty: Medium
Section Ref: 8.1

68. What is wrong with the following function definition?
void erase_file(ifstream infile, ofstream outfile)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
char ch;
while (infile.get(ch))
{
outfile << ch;
}
}

A) The function does not read an end of line character to terminate the while loop.
B) The output from the function does not display all of the characters in the file.
C) The ifstream and ofstream parameters must be pointers.
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) The ifstream and ofstream parameters must be reference parameters.

Ans: D
Title: What is wrong with function definition?
Difficulty: Medium
Section Ref: 8.1

69. Consider the following code snippet:
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
#include
#include
int main()
{
char ch;
int n;
ifstream read_file;
read_file.open(“c:\File.txt”);
while (read_file.get(ch))
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
if (isdigit(ch))
{
read_file.unget();
read_file >> n;
cout << n;
}
}
return 0;
}
What is the output of the program if File.txt contains the text “Year 1775 and Second Month!”?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Year 1775 and Second Month!
B) 1775
C) 1775 Second
D) Year 1775!

Ans: B
Title: What is the output of program if (input file contains) “Year 1775 and Second Month!”?
Difficulty: Medium
Section Ref: 8.2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

70. What is the output of the following code snippet?
cout << setw(5) << setfill('*') << 9;

A) 9
B) ****9
C) 9****
D) *****9
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: B
Title: What is output of snippet (with manipulators)?
Difficulty: Easy
Section Ref: 8.3

71. Which of the following statements displays 78 as 00078?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) cout << setw(5) << 78;
B) cout << left << setw(5) << 78;
C) cout << setw(5) << setfill('0') << 78;
D) None of the options displays the required output.

Ans: C
Title: Which statement displays 78 as 00078?
Difficulty: Medium
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

72. Which of the following statements displays 986.2345 as 986.2?

A) cout << setprecision(1) << 986.2345;
B) cout << fixed << setprecision(1) << 986.2345;
C) cout << setw(5) << 986.2345;
D) None of the options displays the required output.

Ans: B
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which statement displays 986.2345 as 986.2?
Difficulty: Medium
Section Ref: 8.3

73. Consider the variable declarations shown below.
string s = “42”; int n = 0;
Which of the following code snippets converts the string s to an integer n?

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) istringstream strm; strm.str(n); str >> s;
B) ostringstream strm; strm.str(n); str << s;
C) istringstream strm; strm.str(s); strm >> n;
D) ostringstream strm; strm.str(s); strm << n;

Ans: C
Title: Which snippet converts the string s to an integer n?
Difficulty: Medium
Section Ref: 8.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

74. Given the following code snippet, what is the value of the variable num1?
istringstream strm(“12 MOD 2”);
int num1 = 0;
string operation;
strm >> num1 >> operation;

A) 0
B) 12
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) MOD
D) 2

Ans: B
Title: What is value of variable after snippet (that reads from string stream with >>)?
Difficulty: Easy
Section Ref: 8.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
75. Consider the following code snippet:
int main(int argc, char* argv[])
{
for (int i = 0; i < argc; i = i + 2)
{
cout << "Argument " << i + 1 << ":" << argv[i] << endl;
}
return 0;
}
What is the output if the program is saved as ABC.cpp and run as ABC A B C D E F?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

A) Argument 1: ABC
Argument 2: A
Argument 3: B
Argument 4: C
Argument 5: D
Argument 6: E
Argument 7: F
B) Argument 2: B
Argument 4: D
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Argument 6: F
C) Argument 1: ABC
Argument 3: B
Argument 5: D
Argument 7: F
D) There is no output because of a bounds error.

Ans: C
Title: What (are arguments) if program is run as ABC A B C D E F?
Difficulty: Medium
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.5

76. Which of the following statements is true about the given code snippet?
fstream somestream;
int offset = 30;
somestream.open(“File.bin”, ios::in | ios::out | ios::binary);
somestream.seekp(offset);
somestream.seekg(offset + 8);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
somestream.put(‘X’);
somestream.put(‘Y’);
char ch = somestream.get();

A) The characters “X” and “Y” are written into File.bin at locations 30 and 31.
B) The characters “X” and “Y” are written into File.bin at locations 38 and 39.
C) The variable ch stores the character read from location 30 in File.bin.
D) The variable ch stores the character read from location 31 in File.bin.

Ans: A
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: Which is true about snippet (using seekp, seekg, put, get)?
Difficulty: Medium
Section Ref: 8.6

77. For which purpose can you use the following function?
double mystery(fstream& stream, int offset)
{
stream.seekg(offset);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int result = 0;
int num = 0;

for (int i = 0; i < 4; i++)
{
num = stream.get();
if (result < num)
{
result = num;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
return result;
}

A) To calculate the highest of four consecutive bytes read at the offset position in a file
B) To calculate and return an integer from the 4 bytes at the offset position in a file
C) To convert the value of the offset parameter to binary
D) None of the listed items

Ans: A
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: For what can you use this function (that reads bytes)?
Difficulty: Hard
Section Ref: 8.6

78. What is the output from the code snippet below when the input file test.txt is the single line
“Who am I? 24601!”
ifstream in_file;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
char ch;
in_file.open(“test.txt”);
while (in_file.get(ch))
{
if (isdigit(ch))
{
cout << ch;
}
}
A) ?24601!
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) 24601
C) Who am I? !
D) WhoamI?24601!

Ans: B
Title: What is the output from the code snippet that reads character by character from a file?
Difficulty: Easy
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

79. What is the output from the code snippet below when the input file test.txt is the single line
“Who am I? 24601!”
ifstream in_file;
char ch;
in_file.open(“test.txt”);
while (in_file.get(ch))
{
if (isupper(ch))
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << toupper(ch);
}
}
A) hoam
B) 24601
C) ?!
D) WI

Ans: D
Title: What is the output from the code snippet? (reading from file)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 8.2

80. What is the output from the code snippet below when the input file test.txt is the single line
“Sandy (403) 512-6023”
ifstream in_file;
string myword;
in_file.open(“test.txt”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (in_file >> myword)
{
cout << myword << endl;
}
A) Sandy (403) 512-6023
B) Sandy(403)512-5023
C) Sandy
(403)
512
6023
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Sandy
(403)
512-6023

Ans: D
Title: What is the output from the code snippet that reads from a file using the >> operator?
Difficulty: Easy
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

81. What does the following code snippet do for a file of unknown size?
int i = 0;
ifstream in_file;
string myword;
in_file.open(“test.txt”);
while (in_file >> myword)
{
i++;
}
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
cout << i << endl;

A) Counts the number of characters in the file
B) Counts the number of lines in the file
C) Counts the number of words in the file
D) Counts the number of digits in the file

Ans: C
Title: What does the code snippet do for a file input of unknown size?
Difficulty: Easy
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Section Ref: 8.2

82. What does the following code snippet do for a file of unknown size?
int i = 0;
ifstream in_file;
char ch;
in_file.open(“test.txt”);
while (in_file.get(ch))
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
i++;
}
cout << i << endl;

A) Counts the number of characters in the file
B) Counts the number of lines in the file
C) Counts the number of words in the file
D) Counts the number of digits in the file

Ans: A
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What does the code snippet do for a file input of unknown size?
Difficulty: Easy
Section Ref: 8.2

83. What does the following code snippet do for a file of unknown size?
int i = 0;
ifstream in_file;
string mystring;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
in_file.open(“test.txt”);
while (getline(in_file, mystring))
{
i++;
}
cout << i << endl;

A) Counts the number of characters in the file
B) Counts the number of lines in the file
C) Counts the number of words in the file
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) Counts the number of digits in the file

Ans: B
Title: What does the code snippet do for a file input of unknown size?
Difficulty: Easy
Section Ref: 8.2

84. What does the following code snippet do for a file of unknown size?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int i = 0;
ifstream in_file;
string mystring;
in_file.open(“test.txt”);
while (getline(in_file, mystring))
{
i = i + mystring.length();
}
cout << i << endl;

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) Counts the number of characters (except whitespace) in the file
B) Counts the number of lines in the file
C) Counts the number of words in the file
D) Counts the number of digits in the file

Ans: A
Title: What does the code snippet calculate for a file input of unknown size?
Difficulty: Easy
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

85. What is the output from the following code snippet when in file test.txt is the line “If I saw an Aardvark I would scream!”
int main()
{
ifstream in_file;
char ch;
in_file.open(“test.txt”);
int i = 0;
while (in_file.get(ch))
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
if (tolower(ch) == ‘a’)
{
i++;
}
}
cout << i << endl;
}
A) 5
B) 6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) 0
D) 1

Ans: B
Title: What is the output from the code snippet that reads characters from a file?
Difficulty: Medium
Section Ref: 8.2

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
86. What is the output from the following code snippet when in file test.txt is the line “If I saw an Aardvark I would scream!”
int main()
{
ifstream in_file;
char ch;
in_file.open(“test.txt”);
int i = 0;
while (in_file.get(ch))
{
if (ch == ‘a’)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
i++;
}
}
cout << i << endl;
}
A) 5
B) 6
C) 0
D) 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Ans: A
Title: What is the output from the code snippet that reads characters from a file?
Difficulty: Medium
Section Ref: 8.2

87. What is the output from the code snippet below?
int main()
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
int mypow = 1;
for (int i = 0; i < 5; i++)
{
cout << setw(10) << right << mypow << endl;
mypow = mypow * 10;
}
cout << endl;
}
A) 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
10
100
1000
10000
B) 0
1
2
3
4
C) 1
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
10
100
1000
10000
D) 0
1
2
3
4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: A
Title: What is the output from the code snippet with output manipulators?
Difficulty: Easy
Section Ref: 8.3

88. What is the output from the code snippet below?
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int mypow = 1;
for (int i = 0; i < 5; i++)
{
cout << setw(10) << left << mypow << endl;
mypow *= 10;
}
cout << endl;
}
A) 1
10
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
100
1000
10000
B) 0
1
2
3
4
C) 1
10
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
100
1000
10000
D) 0
1
2
3
4

Ans: C
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Title: What is the output from the code snippet with output manipulators?
Difficulty: Easy
Section Ref: 8.3

89. What is the output from the code snippet below?
int main ()
{
int mypow = 1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i < 5; i++)
{
cout << setw(10) << left << i << endl;
mypow *= 10;
}
cout << endl;
}
A) 1
10
100
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
1000
10000
B) 0
1
2
3
4
C) 1
10
100
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
1000
10000
D) 0
1
2
3
4

Ans: D
Title: What is the output from the code snippet with output manipulators?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 8.3

90. What is the output from the code snippet below?
int main()
{
int mypow = 1;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i < 5; i++)
{
cout << setw(10) << right << mypow << endl;
cout << i << endl;
mypow = mypow * 10;
}
cout << endl;
}
A) 1
0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
10
1
100
2
1000
3
10000
4
B) 1
0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
10
1
100
2
1000
3
10000
4
C) 1
0
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
10
1
100
2
1000
3
10000
4
D) 10
101
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
1002
10003
10004

Ans: A
Title: What is the output from the code snippet with output manipulators?
Difficulty: Medium
Section Ref: 8.3

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

91. The istringstream and ostringstream classes are called adapters because
A) they adapt streams to the string interface
B) they adapt character data to the string interface
C) they adapt strings to the stream interface
D) they provide flexibility for formatting data

Ans: C
Title: Why are istringstream and ostringstream called adapters?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Easy
Section Ref: 8.4

92. What does the code snippet below do?
int main()
{
int num = 0;
int prev = 0;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
istringstream iss;
iss.str(“010 14 082 1 15 0820 -151”);
while (iss >> num)
{
if (num > prev)
{
prev = num;
}
}
cout << prev << endl;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
A) Divides the string “010 14 082 1 15 0820 -151” into space-separated words and prints out the one that is alphabetically the smallest
B) Divides the string “010 14 082 1 15 0820 -151” into space-separated words and prints out the one that is alphabetically the largest
C) Divides the string “010 14 082 1 15 0820 -151” into space-separated words and prints out the one that is numerically the smallest
D) Divides the string “010 14 082 1 15 0820 -151” into space-separated words and prints out the one that is numerically the largest

Ans: D
Title: What does the code snippet do?
Difficulty: Medium
Section Ref: 8.4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

93. What is the output of the code snippet below?
int main()
{
int num = 0;
int prev = 0;
istringstream iss;
iss.str(“010 14 082 1 15 0820 -151”);
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
while (iss >> num)
{
if (num > prev)
{
prev = num;
}
}
cout << prev << endl;
}
A) 010
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) -151
C) 0820
D) 820

Ans: D
Title: What is the output of the code snippet (istringstreams)?
Difficulty: Medium
Section Ref: 8.4

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

94. What is the output of the code snippet below?
int main()
{
int num = 0;
int prev = 0;
istringstream iss;
iss.str(“010 14 082 1 15 0820 -151”);
while (iss >> num)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
if (num < prev)
{
prev = num;
}
}
cout << prev << endl;
}
A) 010
B) -151
C) 0820
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) 820

Ans: B
Title: What is the output of the code snippet (istringstreams)?
Difficulty: Medium
Section Ref: 8.4

95. What is the output of the code snippet below?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
int main()
{
int num = 0;
int prev = 0;
istringstream iss;
iss.str(“010 14 test 082 1 15 0820 -151”);
while (iss >> num)
{
if (num > prev)
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
prev = num;
}
}
cout << prev << endl;
}
A) 10
B) 14
C) test
D) 820

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: B
Title: What is the output of the code snippet (istringstreams)?
Difficulty: Hard
Section Ref: 8.4

96. What is the output from the following code snippet?
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 100; i < 106; i = i + 2)
{
ostringstream oss;
oss << "base-" << setw(3) << i;
cout << oss.str() << endl;
}
}
A) base-100
base-102
base-104
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
base-106
B) base-
base-
base-
base
C) base-100base102base104base106
D) base-100
base-102
base-104

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Ans: D
Title: What is the output from the code snippet (output string streams)?
Difficulty: Medium
Section Ref: 8.4

97. What is the output from the following code snippet?
int main()
{
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
for (int i = 0; i < 6; i = i + 2)
{
ostringstream oss;
oss << "base-" << setw(3) << i;
cout << oss.str() << endl;
}
}
A) base-0
base-2
base-4
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; website what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
B) base-000
base-002
base-004
C) base- 0
base- 2
base- 4
D) base- 0base- 2base- 4

Ans: C
Title: What is the output from the code snippet (output string streams)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Medium
Section Ref: 8.4

98. What is the output from the following code snippet?
int main()
{
ostringstream oss;
for (int i = 0; i < 6; i = i + 2)
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
{
oss << "base-" << setw(3) << i;
cout << oss.str() << endl;
}
}
A) base- 0
base- 0base- 2
base- 0base- 2base- 4
B) base- 0
base- 2
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; check here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
base- 4
C) base-000
base-000base-002
base-000base-002base-004
D) base-100
base-102
base-104

Ans: A
Title: What is the output from the code snippet (output string streams)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 8.4

99. The command line argument argc is always at least 1. Why?
A) There is always at least one argument, which is a zero.
B) There is always at least one argument, which is the name of the program
C) There is always at least one argument, which is the user name
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
D) In fact argc can be zero or negative.

Ans: B
Title: Why is the command line argument argc always at least 1?
Difficulty: Easy
Section Ref: 8.5

100. The command line argument argc has a value of 4. What does this mean?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
A) There are three command line arguments stored as elements of argv[1], argv[2], and argv[3]
B) There are three command line arguments stored as character strings that are pointed to by the elements of argv[0], argv[1], and argv[2]
C) There are three command line arguments stored as character strings that are pointed to by the elements of argv[1], argv[2], and argv[3]
D) In fact argc must be less than 4

Ans: C
Title: What does it mean when argc has a value of 4?
Difficulty: Medium
Section Ref: 8.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; click here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

101. What are three common methods for obtaining file names?
I. Reading the file name from user input
II. Hard-coding the file name
III. Constructing the file name using the random number generator
IV. Using a command-line argument
A) I, II, III
B) I, II, IV
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; here what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
C) I, III, IV
D) II, III, IV

Ans: B
Title: What are three common methods for obtaining file names?
Difficulty: Easy
Section Ref: 8.5

what will the following code output? int number = 22; int *var = &number; cout << *var << endl; read more what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
102. What does the following function do?
int calcsomething(fstream& stream, int offset)
{
stream.seekg(offset);
int result = 0;
int base = 1;
for (int i = 0; i < 2; i++)
{
result = result + stream.get() * base;
base = base * 256;
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; get more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
}
return result;
}
A) Calculates the average value of 256 consecutive bytes read at the offset position in a file
B) Calculate a four-byte integer from the four bytes at the offset position in a file
C) Calculates the average value of two consecutive bytes read at the offset position in a file
D) Calculate a two-byte integer from the two bytes at the offset position in a file

Ans: D
Title: What does the function do (reading bytes from a file)?
what will the following code output? int number = 22; int *var = &number; cout << *var << endl; more info what will the following code output? int number = 22; int *var = &number; cout << *var << endl;
Difficulty: Hard
Section Ref: 8.6
what will the following code output? int number = 22; int *var = &number; cout << *var << endl;

Tags: what will the following code output? int number = 22; int *var = &number; cout << *var << endl;, www bcfakes com

Leave a Comment