Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include <stdio.h>
- #include <stdlib.h>
- ////////////////////////////////////////////////////
- int main() //
- {
- int *p = (int*)malloc(4);
- *p = 98;
- printf("*p = %d\n", *p);
- }
- */
- // va_list // Тип данных
- // va_start(); void va_start(va_list param, последний_явный_параметр);
- // va_arg (); type va_arg(va_list param, type);
- // va_end (); void va_end(va_list param);
- #include <stdio.h>
- #include <stdarg.h>
- int sum(int n, ...);
- ////////////////////////////////////////////////////
- int main() //
- {
- int n = sum(2, 10, 7);
- printf("n = %d\n", n);
- n = sum(4, 10, 7, 2, 1); printf("n = %d\n", n);
- }
- /////////////////////////////////////////////////////
- int sum(int n, ...) //
- {
- int nSum = 0;
- va_list T;
- va_start(T, n);
- for(int i = 0; i < n; i++)
- {
- nSum += va_arg(T, int);
- }
- va_end(T);
- return nSum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement