+ 1
How to function in an "if" statement?
plss give an example.... thanks in advance
10 ответов
+ 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";
}
+ 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
}
+ 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) { .... }
+ 2
What language
+ 2
Hatsy Rei i mean the second one....function as an "if'" parameter
+ 1
c++
+ 1
Hatsy Rei can u tell me bro how to pass function in an "if" condition
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
0
Hatsy Rei can u give me example....coz i m new to programming...plss