Variable Number of Arguments in C Language

preview_player
Показать описание
This Video explains about Variable Number of Arguments in C Programming,

Agenda of this Video:
Variable Number of Arguments
step by step methodologies in C

For Complete C & Data Structures
Online Training Please visit:


Mr. Sandeep Soni is a famous Corporate Trainer in Microsoft Azure AZ-104, AZ-204, AZ-305, AZ-400, AZ-500, Containerization in Docker, Microservices - Kubernetes and Azure Service Fabric and more...

For any course-related queries, reach us @ +91 8555823343 / +91 8008327000 Kashmira Shah
Please leave your comment about the videos.

🌐 𝗙𝗼𝗹𝗹𝗼𝘄 𝗨𝘀:
Рекомендации по теме
Комментарии
Автор

but this returns the sum not the average as the functions describes :D

yes_cassi
Автор

The second parameter of va_start is not the number of elements, it is the name of the last parameter before the argument list.

eddiemaune
Автор

nice explanation..keep doing this work..

TravellerMann
Автор

Human or Robot couldn't figure out who was talking...
Secondly, very informal and casual way of teaching.... Can't use word like 'Next what?'

mrinalaich
Автор

That's sum
If you need average :
return sum/cnt;

bahaakrayem
Автор

Thank you so much and greetings from Serbia

jovanasimic
Автор

umm... The function calculates the sum and returns it. This isn't the average at all!
Besides that it was very helpful.

jonjoni
Автор

sir, can you please give us that document from which you were teaching?? please
sir if you do so that will be very helpful

yashshukla
Автор

if you looking better example; variable names are turkish, meaning, topla = sum, sayi1, 2, 3 = number1, 2, 3, ortalama = average.
#include "stdafx.h"
#include <iostream>
#include <stdarg.h>
using namespace std;

int topla(int parametreSayisi, ...);
double ortalamaBul(int parametreSayisi, ...);
int _tmain(int argc, _TCHAR* argv[])
{

int sayi1 = 5, sayi2 = 10, sayi3 = 15;
cout << sayi1 << endl << sayi2 << endl << sayi3 << endl;
cout << topla(2, sayi1, sayi2) << endl;
cout << topla(3, sayi1, sayi2, sayi3) << endl;
cout << topla(3, 10, 20, 30) << endl;

cout << ortalamaBul(2, sayi1, sayi2) << endl;
cout << ortalamaBul(3, sayi1, sayi2, sayi3) << endl;
cout << ortalamaBul(3, 10, 20, 30) << endl;

system("pause");
return 0;
}

int topla(int parametreSayisi, ...)
{
va_list parametrePtr;
va_start(parametrePtr, parametreSayisi);

int toplam = 0;
for (size_t i = 0; i < parametreSayisi; i++)
{
toplam += va_arg(parametrePtr, int);
}
va_end(parametrePtr);
return toplam;
}

double ortalamaBul(int parametreSayisi, ...)
{
va_list parametrePtr;
va_start(parametrePtr, parametreSayisi);
int toplam = 0;
for (size_t i = 0; i < parametreSayisi; i++)
{
toplam += va_arg(parametrePtr, int);
}
va_end(parametrePtr);
return (double)toplam / parametreSayisi;
}

ertugrulsaka
Автор

Can we pass different data types suppose double alongwith int as aarguments ?if yes how can we do that?

princevijaypratap
Автор

what if str data type present in those variable arguments

meghanathreddy
Автор

what happens if i don't pass any argument (int) to the methode average ?

aminamer
Автор

Sir, please make a tutorial on 'Data Structures through C'...

praneeth
Автор

Nice tuto, but it would be better if function Average returns an "average" value...

erivalo
Автор

Great explanation!!! Thanks

Minor comments:
Function should return average instead of sum.
Variable n is redundant, Variable Sum can be used instead.

praveenmhapsekar