Thread: No type and no parameter in prototype and code is compiling

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    5

    No type and no parameter in prototype and code is compiling

    Hi,

    I recently wrote a c program and as you may see i declared function before main but i did not enter any type (int) or parameter. why is it compiling?

    Code:
    #include <stdio.h>
    
    
    void spec();
    
    
    int main()
    {
    unsigned int i;
    int numbers[100];
    int even = 0, odd = 0;
    
    
    spec();
    
    
    }
    
    
    void spec(int i, int numbers[], int even, int odd)
    {
    
    
    printf("%s", "Enter 100 numbers:\n");
    
    
    for (i=0; i<100; i++)
    {
        scanf("%d", &numbers[i]);
    
    
        if (numbers[i] % 2 == 0)
            even++;
        else
            odd++;
        printf("even is %d odd is %d\n", even, odd);
    }
    }
    
    
    // [email protected]

  2. #2
    Registered User
    Join Date
    Dec 2014
    Posts
    11
    because differently to other common programmer languages like jave (k, i only know it for sure from java)
    Code:
     
    void spec();
    doesn't mean no arguments but undefined amount of arguments. so, there is an implementation of the function, but not a according binding one.
    in other words, i think, this program would cause a nice error, but seen by the compiler, there is an definition of your function
    if you wrote
    Code:
     
    void spec(void);
    then there would be an compiler error
    Last edited by fendor; 12-30-2014 at 05:07 PM. Reason: bad grammar

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-27-2009, 06:57 AM
  2. Replies: 17
    Last Post: 06-12-2009, 02:48 PM
  3. declaring a parameter type without naming it?
    By -EquinoX- in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2008, 04:17 AM
  4. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  5. Replies: 12
    Last Post: 01-09-2006, 07:17 AM

Tags for this Thread