Search This Blog

Friday, 14 June 2013

Converting value-returning functions to void functions in c++

#include <iostream.h>

int inc (int);

void main () {
  int i = 3;
  int j;

  j = inc (i);
  cout << j << endl;
}

int inc (int a) {
  return(a+1);
}

/*
// value returning function can be converted to void funcion as follows:
#include <iostream.h>

void inc (int, int&);

void main () {
  int i = 3;
  int j;

  inc(i,j);
  cout << j << endl;
}

void inc (int a, int& b) {
  b = a+1;
}

*/

No comments:

Post a Comment