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
A.6 ... static int x = 1; int y = x * 2; void t1() {...
A.6 ... static int x = 1; int y = x * 2; void t1() {                 y++;                 cout << "x: " << x << " | y: " << y << endl;                 y += 1;                 x -= -1; } void t2() {                 int* x = &y;                 cout << "x: " << x << " | y: " << y << endl; } void t3() {                 int y = x;                 static int x...
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 =...
For different input n, i.e., n = 1, n = 10, n = 20, write down...
For different input n, i.e., n = 1, n = 10, n = 20, write down the final value of counter for function1, function2, and function3. Explain the counter result through math calculation. #include <iostream> using namespace std; void function1(int n){ int count = 0; for(int x = 0; x < 12; x++){ cout<<"counter:"<< count++<<endl; } } void function2(int n){ int count = 0; for(int x = 0; x < n; x++){ cout<<"--- x="<<x<<"------"<<endl; for(int i =0; i < n;...
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...
In C++ void func( int& num1, int* num2) {               int temp = *num2; *num2 =...
In C++ void func( int& num1, int* num2) {               int temp = *num2; *num2 = num1; num1 = temp - *num2; } Given the function definition above what would be the result of the following code? int val1 = 5; int val2 = 8; func(val1, &val2); cout << val1 << “,” << val2 << endl; Answer a) 13, 8    b) 8, 13 c) An error message d) 3, 5 e) 8, 5
int main() { int item; inti; //cout << arr[i] << ";"; cin >> item; int *arr...
int main() { int item; inti; //cout << arr[i] << ";"; cin >> item; int *arr = new int[item]; // for (int x = 0; x < item; x++) // { // } for (int x = 0; x < item; x++) { cin >> arr[x]; if (x > 0) { InsertionSort(x + 1, arr); for (inti = 0; i < x + 1; i++) { cout << arr[i] << ";"; }cout << endl; } } return 0; } can...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
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 =...
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.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT