Thread: error: void value not ignored as it ought to be

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    99

    error: void value not ignored as it ought to be

    I am getting this error: void value not ignored as it ought to be in my program. What is this error and how to remove it?

    Code:
    #include <stdio.h>
    
    void addition(int x, int y);
    
    
    int main(void)
    {
      	 int a = 10; int b = 20;
    	 
    	 int c;
    	 
    	 c = addition(10, 20);
    	 
    	 printf("addition = %d \n",c);
    	 
        return 0;
    }
    
    
    void addition(int x, int y)
       {
    	   unsigned result;
    	   result = x +y ;
       }

  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
    By making your function return an int, and not void.
    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 2012
    Posts
    99
    Quote Originally Posted by Salem View Post
    By making your function return an int, and not void.
    I understood where I was confuse
    addition with no return type but passing value
    Code:
    #include <stdio.h> 
    void addition(int x, int y);
     
     
    int main(void)
    {
         int a = 10; int b = 20;
          
         addition(10, 20);
          
        return 0;
    }
     
    void addition(int x, int y)
       {
           unsigned result;
           result = x +y ;
           
           printf("addition = %d",result);
       }
    addition with return type and passing value
    Code:
    #include <stdio.h> 
    int addition(int x, int y);
     
     
    int main(void)
    {
       
         int c;
          
         c = addition(10, 30);
         
         printf("addition = %d",c);     
        
         return 0;
    }
     
    int addition(int x, int y)
       {
           unsigned result;
           result = x +y ;
           
           
       }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. Your result should be int.
    2. You need a return statement.
    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.

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. void* error
    By Skep_ in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2010, 06:16 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