int main (int argc , char* argv)
int varFunc(float,int, ...);
varFunc(2.36f, 3, "Jai Shri Ram \n","This is not hello world","\nRather a variable argument's program");
int varFunc(float iArg ,int roh , ...)
int i = 0;
while(cout<<i++) // iam printing it to count the number of times this loop is executed before the error is caused
char *rj = va_arg(x,char*);
if(rj == 0) // i think that this statement is never becoming true throughout whole loop
I think there is some problem with that if statement in function varFunc
va_arg will not necessary return null if there is no more arguments to read. Isn't roh the number of strings passed in? In that case you can use that to make sure the loop don't run more than roh iterations.
cout << *rj; will print the first char in the string.
va_arg returns null if you give a null pointer as argument. varFunc(2.36f, 3, NULL);
You have to know, from previous arguments, if there are more arguments to read. You could remember to always pass a null pointer as the last argument, but if you forget to do so things will go wrong. That is one of the problems with va_arg.
If you are using C++11 it could be done much more safely by using variadic templates or std::initializer_list.