Thread: What is the difference between these 2 void

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    47

    What is the difference between these 2 void

    hello friends,


    what is the difference between these two functions

    Code:
    void menu(){
    
    printf("function 1\n");
    
    
    
    
    }

    and this function
    Code:
    void menu(void){
    
    printf("function\n");
    
    
    
    
    }
    normaly if we want to add argument to a function its like this

    Code:
     int Add(int x,int y)              {
                         int sum;
    
                          sum = x + y;
    
                         return sum;               }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > what is the difference between these two functions
    There isn't any difference.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by sash_007 View Post
    hello friends,


    what is the difference between these two functions

    Code:
    void menu(){
    
    printf("function 1\n");
    
    
    
    
    }

    and this function
    Code:
    void menu(void){
    
    printf("function\n");
    
    
    
    
    }
    [...]

    I prefer the second function, as it's input argument is mentioned.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Actually, there is a significant different. In C in particular, and not in C++, if a function declaration/definition argument list is entirely empty, it means that the function can take any number of any type of arguments. For example:
    Code:
    void bar();
    void foo(void);
    
    // Later, inside another function
    bar();
    bar(1, "a", b); // Compiles just file
    foo();
    foo(1, "a", b); // Compilation error!
    Devoted my life to programming...

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    One is a void and one you should avoid.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: invalid conversion from 'const void*' to 'void*'
    By Wahidin Wahid in forum C++ Programming
    Replies: 10
    Last Post: 04-17-2012, 02:17 AM
  2. error invalid conversion from ‘const void*’ to ‘void*’
    By Wahidin Wahid in forum C Programming
    Replies: 3
    Last Post: 03-27-2012, 08:18 PM
  3. difference between void and static void function
    By mahaju in forum C++ Programming
    Replies: 7
    Last Post: 12-27-2011, 04:02 AM
  4. Replies: 12
    Last Post: 03-27-2009, 02:36 PM
  5. Invalid conversion from 'const void*' to 'void*' error
    By prawntoast in forum C Programming
    Replies: 3
    Last Post: 05-01-2005, 10:30 AM

Tags for this Thread