Please help,
I am a beginner in C programming and people have been asking this question to me in many of the interviews.
Please tell me
what does"..." prototype in C mean?
Thanks
RN
Please help,
I am a beginner in C programming and people have been asking this question to me in many of the interviews.
Please tell me
what does"..." prototype in C mean?
Thanks
RN
It represents a variable number of arguments. It's why we can do things like this:
In the first, the function takes one argument. In the second, it has four.Code:printf("Hello World!\n"); printf("%d + %d = %d", 1, 2, 1 + 2 );
Quzah.
Hope is the first step on the road to disappointment.
Code:itsme@itsme:~/C$ cat varargs.c #include <stdio.h> #include <stdarg.h> void sum(int nargs, ...) { va_list ap; int i, sum; va_start(ap, nargs); for(i = sum = 0; i < nargs;++i) sum += va_arg(ap, int); va_end(ap); printf("Received %d ints whose sum is %d.\n", nargs, sum); } int main(void) { sum(1, 86); sum(3, 4, 5, 6); return 0; }Code:itsme@itsme:~/C$ ./varargs Received 1 ints whose sum is 86. Received 3 ints whose sum is 15.
If you understand what you're doing, you're not learning anything.
hEY THERE,
When you write your program, and you have a function inside main....you specify in the beginning of the program that you will be having a function later on that would contain certain number of arguments and also would be returning some type:The compiler would not be confused then when it encountered your function, but if you don't have a prototype, you'd throw your compiler into a state of "entropy"...lol if i may borrow the word..
Look at my representation below "not real program"
I Hope you get the general idea of the prototype..but i'm sure any c text would give you full details and examples..Code:#include <stdio.h> int my_name_is_proto(int a, int b); int well_im_different( double p, double j); // note the semicolon at the end of the prototype..not present in the function declaration itself.... int main () { int ans, ans2, i; ans= ans2 = 0; ---- //your codes in here ans = my_name_is_proto(6, 7);// you invoke the funtion here, ans2 = well_im_different(5.22, 2.33); return (0); } int my_name_is_proto(int a, int b) { ------ //process the function in here } int well_im_different(double p , double j) { --------//process your funtion in here }
Take it easy nd goodluck...
Want2Know,
You didn't answer the original question, and 2 other posters already did answer 6 hours earlier.
thanks a lot guys for ur answer to "...". I appreciate your help
RN