Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ What is the problem with the code snippet below? void cost(int price, int reps) { for (int i = 0; i < reps; i++)

C++

  1. What is the problem with the code snippet below?

void cost(int price, int reps)

{

for (int i = 0; i < reps; i++)

{

cout << price;

}

return;

}

int main()

{

cout << cost(10, 4) << endl;

return 0;

}

  1. The function cost is invoked with the wrong parameters
  2. The function cost uses uninitialized variables
  3. The function cost returns void and therefore cannot be used in a cout statement
  4. The function cost must return an integer value

  1. Which of the following is true about functions?
  1. Functions can have only one parameter and can return only one return value.
  2. Functions can have multiple parameters and can return multiple return values.
  3. Function can have multiple parameters and can return one return value.
  4. Functions can have one parameter and can return multiple return values.

  1. 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?
  1. calc(2, 3.14);
  2. int sum = calc(2, 3);
  3. calc();
  4. int sum = calc("2", "3");

  1. How are variables passed as input to a function?
  1. By using the return statement
  2. By using arguments
  3. By using comments
  4. By using the function name

  1. 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 should be the last statement of this function?

  1. An assignment statement
  2. A return statement
  3. An increment statement
  4. A comparison statement

  1. Which of the following is true about function return statements?
  1. A function can hold multiple return statements, but only one return statement executes in one function call.
  2. A function can hold only one return statement.
  3. A function can hold multiple return statements, and multiple return statements can execute in one function call.
  4. A function can have maximum of two return statements.

  1. Which of the following is the best choice for a return type from a function that prompts users to enter their password?
  1. char
  2. int
  3. string
  4. void

  1. 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;

}

  1. It can be used only in func1().
  2. It can be used in user-defined functions, func1() and func2().
  3. It can be used anywhere in this program.
  4. It can be used in many programs.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago