Say you have this nested if-statement:
int *x;
int y;
if (x == NULL || y > 5)
{
if (x != NULL)
// this should print if x != NULL and y > 5
printf("Hello!\n");
// this should only print if x == NULL.
printf("Goodbye!\n");
}
return 0;
Here, if either statement is true, it will return the same value (0). We should only print "Goodbye" if the left side of the outside if statement is true, regardless of whether the right hand side is true or false. Is it possible to eliminate the inside if-statement by short-circuiting, turning this into a single if-statement?
Aucun commentaire:
Enregistrer un commentaire