Skip to content

Commit

Permalink
default parameters
Browse files Browse the repository at this point in the history
This program is used to learn the default parameters
  • Loading branch information
feihun1 committed Apr 1, 2017
1 parent 156ac46 commit b18bfe0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cpp five.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//The use of the default parameters
#include <iostream>
using namespace std;
char * spy(char *p, int i = 1);
char * spy(char *p, int i)
{
char *q = new char[i+1];
int a;
for ( a = 0; a < i&&p[a]; a++)
{
q[a] = p[a];
}
while (a<=i)
{
q[a++] = '\0';
}
return q;
}
int main()
{
char sth[10];
cin.get(sth, 10);
cin.get();
char *p=spy(sth, 3);
cout << p << endl;
delete[]p;
p=spy(sth);
cout << p << endl;
delete[]p;
cin.get();
return 0;
}

0 comments on commit b18bfe0

Please sign in to comment.