"how to handle variable length argument in c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "how to handle variable length argument in c++" answered properly. Developers are finding an appropriate answer about how to handle variable length argument in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like how to handle variable length argument in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on how to handle variable length argument in c++.
how to handle variable length argument in c++
#include <cstdarg>
#include <iostream>
using namespace std;
// this function will take the number of values to average
// followed by all of the numbers to average
double average ( int num, ... )
{
va_list arguments; // A place to store the list of arguments
double sum = 0;
va_start ( arguments, num ); // Initializing arguments to store all values after num
for ( int x = 0; x < num; x++ ) // Loop until all numbers are added
sum += va_arg ( arguments, double ); // Adds the next value in argument list to sum.
va_end ( arguments ); // Cleans up the list
return sum / num; // Returns the average
}
int main()
{
// this computes the average of 13.2, 22.3 and 4.5 (3 indicates the number of values to average)
cout<< average ( 3, 12.2, 22.3, 4.5 ) <<endl;
// here it computes the average of the 5 values 3.3, 2.2, 1.1, 5.5 and 3.3
cout<< average ( 5, 3.3, 2.2, 1.1, 5.5, 3.3 ) <<endl;
}
Source: www.cprogramming.com
All those coders who are working on the C++ based application and are stuck on how to handle variable length argument in c++ can get a collection of related answers to their query. Programmers need to enter their query on how to handle variable length argument in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to handle variable length argument in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of how to handle variable length argument in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "how to handle variable length argument in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to handle variable length argument in c++ resolved professionally and stay updated to the latest C++ updates.