-
Conditional Assignments
Sometimes, you’ll have a scenario with two variables, and you need to use one of them based on a simple test. Rather than a long and awkward if / else statement, C allows the use of the ? : form. It is perfectly acceptable to write: int i,j,k,l; … i = (j > 5? k […]
-
Preprocessor #s, ##s, and other weird stuff
In the post on strings for enums , I used two types of pound symbols in the preprocessor macros: # and ##. Here’s some more detail:
-
i++ Incremements and Execution Sequence
Quiz: What will the following code print? int i = 5; printf(“%d “, i++ * i++); printf(“%d\n”, i);
-
Multiple Pointer Declarations
Quick quiz: What does the following code do: char* p1, p2 ?
-
Creating an array of strings for an enum
A common issue in writing C based test tools is the desire to be able to show a user a list of all enums. This, of course, is technically impossible, as the mapping from enum to int is one way only. However, the following trick lets you create a two dimensional character array who’s index […]