char *array and char array[]

The declaration and initialization declares a pointer array and make it point to a constant array of 31 characters. The declaration and initialization declares an array of characters, containing 31 characters. And yes, the size of the arrays is 31, as it includes the terminating ‘\0’ character. Laid out in memory, it will be something like this for the … Read more

Python: list of lists

Lists are a mutable type – in order to create a copy (rather than just passing the same list around), you need to do so explicitly: However, list is already the name of a Python built-in – it’d be better not to use that name for your variable. Here’s a version that doesn’t use list as a variable name, … Read more

Regex: ignore case sensitivity

Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it: Check the documentation for your language/platform/tool to find how the matching modes are specified. If you want only part of the regex to be case insensitive (as my original answer presumed), then you … Read more

‘was not declared in this scope’ error

The scope of a variable is always the block it is inside. For example if you do something like The solution is to define y outside of the if blocks In your program you have to move the definition of y and c out of the if blocks into the higher scope. Your Function then … Read more

How to write inline if statement for print?

Python does not have a trailing if statement. There are two kinds of if in Python: if statement: if condition: statement if condition: block if expression (introduced in Python 2.5) expression_if_true if condition else expression_if_false And note, that both print a and b = a are statements. Only the a part is an expression. So … Read more

Usage and Syntax of std::function

std::function is a type erasure object. That means it erases the details of how some operations happen, and provides a uniform run time interface to them. For std::function, the primary1 operations are copy/move, destruction, and ‘invocation’ with operator() — the ‘function like call operator’. In less abstruse English, it means that std::function can contain almost any object that acts like a function … Read more