Hi I have doubt . Can we return the some data from boolean Function in C

For Example

bool add( int a, int b)
   int C;

  C = a + b;

return C;

Is it possible in C

9 Years
Discussion Span
Last Post by monkey_king

You can, but you'll probably get a conversion warning and the result will be forced into a boolean range (in the case of int, zero is false and non-zero is true).


why would you want to return some integer instead of true/false? If bool is inappropriate for that function then just change the return type of the function.


yeah, the point of calling a boolean function aka bool is to call a function that will answer the question is this true or false... in your function you are asking function add whether a plus b does not equal zero.

if thats what you want to do then great if not change it to

int add( int a , int b ) < that is a function that returns an integer
bool add( int a, int b ) < a function that returns a boolean character aka true or false


On a general note, (anyone correct me if I am wrong).

The bool type is part of the c99 standard, and is as such not expected to be as portable.

I've never found a use for the bool type that the short int or char couldn't solve.
The bool still takes 1byte of space which is the same as 1char.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.