null_pointer_check

Run Settings
LanguageC
Language Version
Run Command
#include <stdint.h> #include <stdio.h> #define ZERO 0 int main() { int* pointer; printf("Null pointer checks\n"); pointer = NULL; printf(" pointer = NULL\n"); // ALWAYS VALID printf("\tpointer == NULL\t\t"); (pointer == NULL) ? printf("true\n") : printf("false\n"); printf("\tpointer == 0\t\t"); (pointer == 0) ? printf("true\n") : printf("false\n"); printf("\t(!pointer)\t\t"); (!pointer) ? printf("true\n") : printf("false\n"); // POSSIBLY VALID printf("\tpointer == '\\0'\t\t"); (pointer == '\0') ? printf("true\n") : printf("false\n"); printf("\tpointer == (void*)0\t"); (pointer == (void*)0) ? printf("true\n") : printf("false\n"); // INVALID int x = 0; printf("\tx = 0; pointer == x\t"); (pointer == x) ? printf("true (warning)\n") : printf("false\n"); // invalid check because `zero` is not a constant literal 0 // Should generate at least a warning according to c standard. return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines