Script example 4: sample04.C

// To test this code, do 
//   $ root sample04.C+
// Note the difference with the result with  
//   $ root sample04.C
//
// This is a sample link to  home page of LC Physics Study group 
//
// Link to JSFSteer is created automatically
//
// 
/* Image can be inserted using raw html command

*/
// 
//
#include <iostream>
using namespace std;

// -------------------------------------------------
void swap_by_address(int *a, int *b){
    int tmp=*a;     *a = *b ;   *b = tmp;
}

// -------------------------------------------------
void swap_by_reference(int &a, int &b){
    int tmp=a;    a=b;   b=tmp;
}

// -------------------------------------------------
void swap_test(){
   int a=20;
   int b=50;
   swap_by_address(&a, &b);
   cout << " a=" << a << " b=" << b << endl;
   swap_by_reference(a,b);
   cout << " a=" << a << " b=" << b << endl;
}

// -------------------------------------------------
void sample04()
{
  int i=1;
  for(int k=0;k<20;k++){
    int i=2*k;
    if( k == 19 ) {
      cout << "Last value of i is " << i << endl;
    }
  }
  cout << "i after loop is " << i << endl;

  swap_test();

}


ROOT page - Home page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.