Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      va_copy

      From cppreference.com
      <c‎ |variadic
       
       
       
      Defined in header<stdarg.h>
      void va_copy( va_list dest, va_list src);
      (since C99)

      Theva_copy macro copiessrc todest.

      va_end should be called ondest before the function returns or any subsequent re-initialization ofdest (via calls tova_start orva_copy).

      Contents

      [edit]Parameters

      dest - an instance of theva_list type to initialize
      src - the sourceva_list that will be used to initializedest

      [edit]Expanded value

      (none)

      [edit]Example

      Run this code
      #include <stdio.h>#include <stdarg.h>#include <math.h> double sample_stddev(int count, ...){/* Compute the mean with args1. */double sum=0;    va_list args1;    va_start(args1, count);    va_list args2;    va_copy(args2, args1);/* copy va_list object */for(int i=0; i< count;++i){double num= va_arg(args1,double);        sum+= num;}    va_end(args1);double mean= sum/ count; /* Compute standard deviation with args2 and mean. */double sum_sq_diff=0;for(int i=0; i< count;++i){double num= va_arg(args2,double);        sum_sq_diff+=(num-mean)*(num-mean);}    va_end(args2);returnsqrt(sum_sq_diff/ count);} int main(void){printf("%f\n", sample_stddev(4,25.0,27.3,26.9,25.7));}

      Possible output:

      0.920258

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.16.1.2 The va_copy macro (p: 270)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.15.1.2 The va_copy macro (p: 250)

      [edit]See also

      accesses the next variadic function argument
      (function macro)[edit]
      ends traversal of the variadic function arguments
      (function macro)[edit]
      holds the information needed byva_start,va_arg,va_end, andva_copy
      (typedef)[edit]
      enables access to variadic function arguments
      (function macro)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/variadic/va_copy&oldid=117388"

      [8]ページ先頭

      ©2009-2025 Movatter.jp