Back
Close

Computing with Data

elgeish
33.3K views

Scope of Function Variables

#include <iostream>
#include <string>
using namespace std;
// return a * b
int multiply_two(int a, int b) {
int c = a * b;
return c;
}
int main() {
cout << multiply_two(2, 3) << endl; // prints 6
int b = 4;
int c = 5;
cout << multiply_two(b, c) << endl; // prints 20
cout << c << endl; // print value of local c (5)
return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants