Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Scope of Variables Using Call-by-Value

% cat call_val.cpp
#include<iostream>
using namespace std;

void foo( int score );

int main()
{
   int score = 5;

   cout << "\nIn main, score = " << score << endl;

   // call foo using call-by-value
   foo( score );

   cout << "\nIn main, score = " << score << endl;

   return 0;

}

void foo( int score )
{
  cout << "\nIn foo, score = " << score << endl;

  score = 10;

  cout << "\nIn foo, score = " << score << endl;

  return;

}
% g++ call_val.cpp
% a.out

In main, score = 5

In foo, score = 5

In foo, score = 10

In main, score = 5

 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming