what does"..." prototype in C mean?

This is a discussion on what does"..." prototype in C mean? within the C Programming forums, part of the General Programming Boards category; Please help, I am a beginner in C programming and people have been asking this question to me in many ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    21

    Cool what does"..." prototype in C mean?

    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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It represents a variable number of arguments. It's why we can do things like this:
    Code:
    printf("Hello World!\n");
    printf("%d + %d = %d", 1, 2, 1 + 2 );
    In the first, the function takes one argument. In the second, it has four.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    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.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    4

    what is a prototype?

    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"

    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
    }
    I Hope you get the general idea of the prototype..but i'm sure any c text would give you full details and examples..

    Take it easy nd goodluck...

  5. #5
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    Want2Know,

    You didn't answer the original question, and 2 other posters already did answer 6 hours earlier.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    21

    Smile thankyou

    thanks a lot guys for ur answer to "...". I appreciate your help

    RN

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  2. Function prototype questions
    By Kayoss in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2005, 04:27 PM
  3. prototype poblem
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 10-30-2005, 09:01 AM
  4. Prototype syntax for sub-class constructor
    By starkhorn in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2004, 07:33 AM
  5. call to function without prototype
    By lgbeeb in forum C Programming
    Replies: 2
    Last Post: 03-25-2003, 11:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21