0

How can I use a function in a condition and check whether it's true or not?

2nd Mar 2022, 6:33 PM
Basma M
5 Answers
+ 4
Xx Yyy Your function should return a value then you can use that function in a condition. Like: bool isPalindrome() { return true; } Now use in condition like: if (isPalindrome ()) { cout << "Palindrome"; }
2nd Mar 2022, 6:38 PM
AĶ¢J
AĶ¢J - avatar
+ 1
And if it wasn't a palindrome I will use else?
2nd Mar 2022, 7:25 PM
Basma M
+ 1
Xx Yyy There might be 2 situation one is yes and one is no so if condition is true then if block will execute otherwise else block.
2nd Mar 2022, 7:38 PM
AĶ¢J
AĶ¢J - avatar
0
if (function()) {...} Note that function must return a Boolean or something that can be understood as a Boolean (e.g. an int)
4th Mar 2022, 4:59 PM
Hiba al-Sayf
Hiba al-Sayf - avatar