C interview questions
Questions that used to come up in IT interviews, pointers, linked lists, and a few small programs. Each one has a short, clean answer that compiles on GCC.
-
const char *p vs char * const p vs const char * const p
const char *p, char * const p, const char * const p, what each one actually means.
-
What does *p++ do?
Does *p++ move the pointer, or change the value it points at?
-
Is *(*(p+i)+j) the same as p[i][j]?
Why *(*(p+i)+j) == p[i][j], and the num[i] == i[num] trick.
-
What operations are valid on pointers?
The arithmetic and comparisons that are actually legal on pointers.
-
Array of pointers vs pointer to an array
Two things that look alike and behave very differently.
-
Delete a node given only a pointer to it
Deleting a node when all you have is a pointer to it.
-
Turn an ordered binary tree into a circular doubly linked list
Flattening an ordered binary tree into a circular doubly linked list.
-
Check for a power of two in one line
The classic one-line power-of-two check.