Why do we use NULL in strtok()?

strtok is part of the C library and what it does is splitting a C null-delimited string into tokens separated by any delimiter you specify. The first call to strtok must pass the C string to tokenize, and subsequent calls must specify NULL as the first argument, which tells the function to continue tokenizing the … Read more

Can a constructor return a NULL value?

I agree with everyone else that you should use exceptions, but if you do really need to use NULL for some reason, make the constructor private and use a factory method: static CMyClass* CMyClass::create(); This means you can’t construct instances normally though, and you can’t allocate them on the stack anymore, which is a pretty … Read more

Oracle: How to count null and non-null rows

COUNT(expr) will count the number of rows where expr is not null, thus you can count the number of nulls with expressions like these: SELECT count(a) nb_a_not_null, count(b) nb_b_not_null, count(*) – count(a) nb_a_null, count(*) – count(b) nb_b_null, count(case when a is not null and b is not null then 1 end)nb_a_b_not_null count(case when a is … Read more

Is there a platform or situation where dereferencing (but not using) a null pointer to make a null reference will behave badly?

Classically, compilers treated “undefined behavior” as simply an excuse not to check for various types of errors and merely “let it happen anyway.” But contemporary compilers are starting to use undefined behavior to guide optimizations. Consider this code: int table[5]; bool does_table_contain(int v) { for (int i = 0; i <= 5; i++) { if … Read more

Is it possible in Java to check if objects fields are null and then add default value to all those attributes?

You can use reflection to iterate over the object’s field, and set them. You’d obviously need some sort of mapping between types or even field names and required default values but this can be done quite easily in a loop. For example: for (Field f : obj.getClass().getFields()) { f.setAccessible(true); if (f.get(obj) == null) { f.set(obj, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)