xxxxxxxxxx
// Single line if statement in C
// This can be useful if you are writing a very simple if statent
// with no else.
int main(int argc, char** argv) {
if (/* CONDITION */) do_something();
// As you can see, there is no else, and also no brackets.
return 0;
}
xxxxxxxxxx
str = arraeck(a, n) ? "YES" : "NO";
printf(arraeck(a, n) ? "YES" : "NO");
xxxxxxxxxx
// single line condition in C:
// condition ? value_if_true : value if false
// example:
int a= 0;
int b= a==0 ? 100 : 200;
// the value of b will be 100
xxxxxxxxxx
#include <stdio.h>
int main()
{
printf("Hello World\n");
char str1[5] = "test";
char str2 = NULL;
printf("\nresult: %s", str1 ? "str is not empty" : "str is empty");
printf("\nresult: %s", str2 ? "str is not empty" : "str is empty");
return 0;
}