A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FFunction%2Fdefault_arguments</id>
		<title>C++ Tutorial/Function/default arguments - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FFunction%2Fdefault_arguments"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Function/default_arguments&amp;action=history"/>
		<updated>2026-04-10T23:24:59Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Function/default_arguments&amp;diff=2465&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Function/default_arguments&amp;diff=2465&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Function/default_arguments&amp;diff=2466&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Function/default_arguments&amp;diff=2466&amp;oldid=prev"/>
				<updated>2010-05-25T10:29:46Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Ambiguous function call with function with default parameter value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int myfunc(int i);&lt;br /&gt;
int myfunc(int i, int j=1);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; myfunc(4, 5) &amp;lt;&amp;lt; &amp;quot; &amp;quot;; // unambiguous&lt;br /&gt;
  //cout &amp;lt;&amp;lt; myfunc(10); // ambiguous&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
int myfunc(int i)&lt;br /&gt;
{&lt;br /&gt;
  return i;&lt;br /&gt;
}&lt;br /&gt;
int myfunc(int i, int j)&lt;br /&gt;
{&lt;br /&gt;
  return i*j;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;20 &amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Demonstrate default arguments==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
using namespace std;  &lt;br /&gt;
 &lt;br /&gt;
void f(int x = 0, int y = 100); &lt;br /&gt;
 &lt;br /&gt;
int main()  &lt;br /&gt;
{  &lt;br /&gt;
  f(1, 2); &lt;br /&gt;
 &lt;br /&gt;
  f(10); &lt;br /&gt;
 &lt;br /&gt;
  f(); &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
void f(int x, int y) &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;x: &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, y: &amp;quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;x: 1, y: 2&lt;br /&gt;
x: 10, y: 100&lt;br /&gt;
x: 0, y: 100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==demonstrates missing and default arguments==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;   &lt;br /&gt;
  using namespace std;   &lt;br /&gt;
    &lt;br /&gt;
  void repchar(char=&amp;quot;*&amp;quot;, int=45);   &lt;br /&gt;
  int main(){   &lt;br /&gt;
     repchar();                     &lt;br /&gt;
     repchar(&amp;quot;=&amp;quot;);                  &lt;br /&gt;
     repchar(&amp;quot;+&amp;quot;, 30);              &lt;br /&gt;
     return 0;   &lt;br /&gt;
  }   &lt;br /&gt;
  void repchar(char ch, int n)      &lt;br /&gt;
  {                              &lt;br /&gt;
     for(int j=0; j&amp;lt;n; j++)      &lt;br /&gt;
        cout &amp;lt;&amp;lt; ch;              &lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Function with two regular parameters and one parameter with default value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
#include &amp;lt;cstring&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
void f(char *s1, char *s2, int len = 0); &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  char str1[80] = &amp;quot;This is a test&amp;quot;; &lt;br /&gt;
  char str2[80] = &amp;quot;0123456789&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  f(str1, str2, 5); &lt;br /&gt;
  f(str1, str2); &lt;br /&gt;
  return 0; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
void f(char *s1, char *s2, int len) &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; s1;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; len &amp;lt;&amp;lt; &amp;quot; &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; s2;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;This is a test 5 0123456789This is a test 0 0123456789&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use two default parameter values==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 int f(int length, int width = 25, int height = 1);&lt;br /&gt;
 &lt;br /&gt;
 int main()&lt;br /&gt;
 {&lt;br /&gt;
     int length = 100;&lt;br /&gt;
     int width = 50;&lt;br /&gt;
     int height = 2;&lt;br /&gt;
     int area;&lt;br /&gt;
 &lt;br /&gt;
     area = f(length, width, height);&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;First time area equals &amp;quot; &amp;lt;&amp;lt; area &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
     area = f(length, width);&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;Second time area equals &amp;quot; &amp;lt;&amp;lt; area &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
     area = f(length);&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;Third time area equals &amp;quot; &amp;lt;&amp;lt; area &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 int f(int length, int width, int height)&lt;br /&gt;
 {&lt;br /&gt;
     return (length * width * height);&lt;br /&gt;
 }&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;First time area equals 10000&lt;br /&gt;
Second time area equals 5000&lt;br /&gt;
Third time area equals 2500&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using multiple default parameter values: defaults for reference parameters==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::string;&lt;br /&gt;
void show_data(const int data[], int count = 1,&lt;br /&gt;
            const string&amp;amp; title = &amp;quot;Data Values&amp;quot;, int width = 10, int perLine =5);&lt;br /&gt;
int main() {&lt;br /&gt;
  int data[] = {1, 2, 3, 4};&lt;br /&gt;
  int dataItem = 99;&lt;br /&gt;
  show_data (&amp;amp;dataItem);&lt;br /&gt;
  dataItem = 13;&lt;br /&gt;
  show_data(&amp;amp;dataItem, 1, &amp;quot;Unlucky for some!&amp;quot;);&lt;br /&gt;
  show_data(data, sizeof data/sizeof data[0]);&lt;br /&gt;
  show_data(data, sizeof data/sizeof data[0], &amp;quot;title 1&amp;quot;);&lt;br /&gt;
  show_data(data, sizeof data/sizeof data[0], &amp;quot;title 2&amp;quot;, 14);&lt;br /&gt;
  show_data(data, sizeof data/sizeof data[0], &amp;quot;title 3&amp;quot;, 14, 4);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
void show_data (const int data[], int count, const string&amp;amp; title,int width, int perLine) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; title;                    &lt;br /&gt;
  cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; perLine;&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; width &amp;lt;&amp;lt; data[2];    &lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Data Values&lt;br /&gt;
5&lt;br /&gt;
102&lt;br /&gt;
Unlucky for some!&lt;br /&gt;
5&lt;br /&gt;
102&lt;br /&gt;
Data Values&lt;br /&gt;
5&lt;br /&gt;
103&lt;br /&gt;
title 1&lt;br /&gt;
5&lt;br /&gt;
103&lt;br /&gt;
title 2&lt;br /&gt;
5&lt;br /&gt;
143&lt;br /&gt;
title 3&lt;br /&gt;
4&lt;br /&gt;
143&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>