What is output by the following program segment when functio

What is output by the following program segment when function f3 is called twice? void f3() {static int x = 0; x++; cout

Solution

Program:

#include <iostream>
using namespace std;
int f3()
{
static int x=0;
x++;
  cout<<\" x is: \"<< x <<\"\ \";
}

int main() {
static int n=0;
n=f3(); // Here first time we are calling f3() function
n=f3(); // Here we are calling f3() function twice
}

Output:

x is: 1 // Here value of x s 1 when calling f3() function for first time
x is: 2 // Here value of x is 2 when calling f3() function twice

 What is output by the following program segment when function f3 is called twice? void f3() {static int x = 0; x++; cout SolutionProgram: #include <iostream

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site