What will the following program print as its output? void f(int x, int y) { x = y * 2; y = 0; cout << x << "," << y << endl; } int main() { int a = 1, b = 3; cout << a << "," << b << endl; f(b,a); cout << a << "," << b << endl; return 0; }
Added by Laura B.
Close
Step 1
The program starts with the main function. Show more…
Show all steps
Your feedback will help us improve your experience
Dominador Tan and 63 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
What is the output of the following code: int x=15; if(x%2)cout<<++x; else cout<< x;
Neel P.
Given the following function definition: void calc(int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A. 1 2 3 B. 1 6 3 C. 3 6 3 D. 1 14 9
Akash M.
#include<iostream> using namespace std; /*trace the program*/ int func(int& a, int b) { if (a > b) { a = b++; b += 2; return b; } else { a = --b; b -= 2; return b; } } int main() { int x = 2, y = 4, z = 0; cout << "X = " << x << " Y = " << y << " Z = " << z << endl; z = func(x, y); cout << "X = " << x << " Y = " << y << " Z = " << z << endl; x = func(y, z); cout << "X = " << x << " Y = " << y << " Z = " << z << endl; system("pause"); return 0; }
Deepak K.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD