Starting Out With C++, Early Objects (Looseleaf)
Starting Out With C++, Early Objects (Looseleaf)
8th Edition
ISBN: 9780133427622
Author: GADDIS
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 14, Problem 7RQE

Predict the Output

7. What is the output of the following programs?

A) #include <iostream>

using namespace std;

int function(int);

int main()

{

int x = 10;

cout << function(x) << endl;

return 0;

}

int function(int num)

{

if (num <= 0)

return 0;

else

return function(num - 1) + num;

}

B) #include <iostream>

using namespace std;

void function(int);

int main()

{

int x = 10;

function(x);

return 0;

}

void function(int num)

{

if (num > 0)

{

for (int x = 0; x < num; x++)

cout << '*';

cout<< endl;

function(num - 1);

}

}

C) #include <cstdlib>

#include <string>

#include <iostream>

using namespace std:

void function(string str, int pos);

int main(int argc, char** argv)

{

string names = "Adam and Eve";

function(names, 0);

return 0;

}

void function (string str. int pos)

{

if (pos < str. length())

{

function(str, pos+1);

cout << str[pos]:

}

}

Blurred answer
Students have asked these similar questions
Assume that the declarations for two functions look as follows:  int Function1(double x); 2.void Function2(double x); Give some sample code that would show how each function could be used.
C++ programming 48.In the function prototype void action(int& value); The argument value is said to be a ___________ parameter. 49.In the previous problem, suppose the function action updated its argument. True or false: the variable value in the caller would be updated. ________________ 50.True or false: the following two prototypes represent valid overloaded functions _________:double fna(double,int);float fna(float,int);
Playing with Functions: Write a Javascript program to check if the argument passed to any function is a function type or not. I.e. Create a function check which takes a argument and check if that argument is a function or not.

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY