Program:
#include <iostream>
using namespace std;
int f3()
{
static int x=0;
x++;
cout<<" x is: "<< x <<"\n";
}
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()...
C
Programming
1 point Given the following code, if Static() is called twice, what will be printed to the screen from the second call? int x = 10; void Print(int x) printf("%d", x); } { void Output() { printf("%d", x); > void Static) { static int x = 0; printf("%d", x++); } Type your answer 8 1 point Given the following code, if Static() is called, what will be printed to the screen? int x = 10; void Print(int x)...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
What is the output from the following code segment? Output from PRINTLINE 1: public static void Main(){ int x = 38; int y = 45; int z = DoIt(ref x, ref y); PRINTLINE(x + “ “ + y + “ “ + z); // PRINTLINE 1 } static int DoIt(ref int a, ref int b) { a /= 8; b /= 7; PRINTLINE(a + “ “ + b); // PRINTLINE 2 return (a + b);...
18 C++
1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is
What is the output of the PRINTLINE2 from the following code segment? public static void Main(){ int x = 15; int y = 55; int z = DoIt(ref x, ref y); PRINTLINE(x + “ “ + y + “ “ + z); // PRINTLINE 1 } static int DoIt(ref int a, ref int b) { a += 22; b -= 12; PRINTLINE(a + “ “ + b); // PRINTLINE 2 return (a - b); }
What is the output of the following program segment? int count = 5; while(--count > 0) cout << count << " "; cout << endl;
Write the output of the following function assuming it was called with the given function call a. Call: fun(4, 10); fo void fun (int a, int b) cout << b a << endl; if(a >= b) { 나 cout < "boo\n"; return; fun(a 1, b 1); cout << a << endl;
What will be the output of the following code segment after the user enters 0 at the keyboard in a C++ program? int x = -1; cout << "Enter a 0 or 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;
Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...
What is the output of the following program? int main(void) { int x, y, z; x = 5; y= test(x); z= x + y; cout<< setw(4)<<x <<” + “<<setw(4)<<y<<”=” << setw(4)<<z<<endl; return 0; } int test (int x) { int w; w = x + 10; return (w); }