QUESTION 21
What does typedef do?
2 marksAnswer
It introduces another name for an existing type. It does not allocate an object or create a distinct incompatible type by itself.
QUESTION 21
It introduces another name for an existing type. It does not allocate an object or create a distinct incompatible type by itself.
QUESTION 22
typedef gives a type a convenient alias that can make declarations easier to read.
typedef unsigned long Count;
typedef struct { int x, y; } Point;
Point p = {2, 3};Count is an alias for unsigned long. Point names the stated structure type, so Point p declares an object without repeating struct before the type name. The typedef declaration itself is not the object p and does not store a coordinate.
typedef int *IntPointer; makes both a and b pointers in IntPointer a, b;. This differs from int *a, b;, where only a is a pointer. However, hiding a pointer can also obscure const behaviour: const IntPointer qualifies the pointer object, not the pointed-to int. Keep aliases understandable.
typedef is not a preprocessor #define. It participates in C’s declaration and type rules rather than merely replacing tokens. It does not automatically change a data structure’s runtime performance or allocate new storage. A type alias can improve readability, but the underlying type’s size, range and operations still apply.