Question

Given the following function in C++: int main(void) { int a = 2; int b =...

Given the following function in C++:

int main(void) {

int a = 2;

int b = myFunction(a);

a = b + 1;

b = myFunction(a);

cout << ”b = ” << b << endl;

return 0;

}

int z = myFunction(int x) {

static int n = 0;

n = n + 1;

int z = x + n;

return z;

}

What is printed by the cout on the screen?

Homework Answers

Answer #1

Case:1

This program is getting Some syntax Errors

main.cpp: In function ‘int main()’: main.cpp:4:21: error: ‘myFunction’ was not declared in this scope int b = myFunction(a); ^ main.cpp:7:1: error: ‘cout’ was not declared in this scope cout << "b = " << b << endl; ^~~~ main.cpp:7:24: error: ‘endl’ was not declared in this scope cout << "b = " << b << endl; ^~~~ main.cpp: At global scope: main.cpp:10:20: error: expected primary-expression before ‘int’ int z = myFunction(int x) { ^~~ main.cpp:10:25: error: ‘myFunction’ was not declared in this scope int z = myFunction(int x) {

Case:2

If we ignore that

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The function martian() has a prototype of: void martian(int ch); and an implementation of: void (int...
The function martian() has a prototype of: void martian(int ch); and an implementation of: void (int ch) { printf("%c" ,ch); return; } it is called from main as int md= 0x45; martian(md); What is printed on the screen?
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int num2; cout << fixed << showpoint << setprecision(2); cout << "Enter two integers: "; cin >> num1 >> num2; cout << endl; if (num1 != 0 && num2 != 0) cout << sqrt(abs(num1 + num2) + 0.5) << endl; else if (num1 != 0) cout << floor(num1 + 0.5) << endl; else if (num2 != 0) cout << ceil(num2 + 0.5) << endl; else...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;     float f=2.22;     float h=-7.5;     char a='S';     char b='M';     cout<<i<<"\t"<<j<<"\t"<<k<<endl;     Cout<<f<<"\t"<<h<<endl;     cout<<a<<"\t"<<b<<endl;     return 0;     }
Given the following function:      int C(int n, int k)                  {              
Given the following function:      int C(int n, int k)                  {                     if (k= =0) return 1;                        else return (C(n-1, k-1) * n)/k;                                       } What type of function is this? Recursive or Iterative. Explain your answer.
Explain each line in main (you can put it in the comments) and explain why the...
Explain each line in main (you can put it in the comments) and explain why the output looks how it looks. #include <iostream> using namespace std; class A { public:        A()        {               n=0;        }        A(int x)        {               n=x;        }        void f()        {               n++;        }        void g()        {               f();               n=n*2;               f();        }        int k()        {               return n;        }       ...
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
C++ visual studios this function has to run twice. and the "count" variable needs to be...
C++ visual studios this function has to run twice. and the "count" variable needs to be "2" on the second run. How can i do that? The parameters can not change as well void printArray(const int *array, int n) {    int count = 1;    char check;    if (check == 'k')    {        count++;    }    cout << "Value " << count << " array contents." << endl;    cout << "------------------------" << endl;   ...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...