Pass string (char *) into a function : Function Parameters « Function « C++






Pass string (char *) into a function

Pass string (char *) into a function
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void center(char *s);

int main()
{
  center("www.java2s.com");
  center("www.java2s.com");

  return 0;
}

void center(char *s)
{
  int len;

  len = 40+(strlen(s)/2);

  cout << setw(len) << s << '\n';
}



           
       








Related examples in the same category

1.Function parametersFunction parameters
2.Function: reference version and pointer versionFunction: reference version and pointer version
3.Passing Arguments by ValuePassing Arguments by Value
4.Function uses two argumentsFunction uses two arguments
5.Passing Arguments by ReferencePassing Arguments by Reference
6.Passes the variable to be doubled by referencePasses the variable to be doubled by reference
7.Passed by value and passed by referencePassed by value and passed by reference
8.Demonstrates the use of return values with reference type.Demonstrates the use of return values with reference type.
9.Expressions with reference type exemplified by string assignments.