+ 1

How to function in an "if" statement?

plss give an example.... thanks in advance

9th Sep 2018, 10:12 AM
Ashish
Ashish - avatar
10 Answers
9th Sep 2018, 10:15 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 5
Ashish if statements require boolean values to be evaluated as a condition, so you need a function which returns a boolean. E.g. bool always_true() { return true; } // in main if (always_true()) { std::cout << "Yes"; }
9th Sep 2018, 11:04 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Ashish I'm not too sure what you mean by "pass function in if". Can you type a snippet and share it so I get what you are trying to achieve? For now, I imagine: if (something) { // function call here } or do you mean if (function()) { // body }
9th Sep 2018, 10:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Ashish If statements will always evaluate its arguments as boolean. You can feed it with functions returning integers, or just integers or other datatype which can be casted to boolean. if (3939) { .... }
9th Sep 2018, 1:36 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
What language
9th Sep 2018, 10:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hatsy Rei i mean the second one....function as an "if'" parameter
9th Sep 2018, 11:02 AM
Ashish
Ashish - avatar
+ 1
c++
9th Sep 2018, 10:15 AM
Ashish
Ashish - avatar
+ 1
Hatsy Rei can u tell me bro how to pass function in an "if" condition
9th Sep 2018, 10:36 AM
Ashish
Ashish - avatar
0
Hatsy Rei is there any other situation where if statements dont requure boolean values....if yes ...can u give example of that too...tthat woukd be very kind of u
9th Sep 2018, 1:33 PM
Ashish
Ashish - avatar
0
Hatsy Rei can u give me example....coz i m new to programming...plss
9th Sep 2018, 1:43 PM
Ashish
Ashish - avatar