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

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

Thanks for your people helping


Thanks

Yuvaraj.R

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.