Advertisement
AnyaAS

Функция с меняющимся количеством принимаемых параметров

Mar 31st, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int Sum(int a, ...)
  7. {
  8.     int *p = &a;
  9.     int sum = 0;
  10.     while (*p)
  11.     {
  12.         sum = sum + (*p);
  13.         p++;
  14.     }
  15.     return sum;
  16. }
  17.  
  18. int _tmain(int argc, _TCHAR* argv[])
  19. {
  20.     cout << Sum(5, 10, 5, NULL) << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement