Quick Test 19: typedef

1. What is typedef used for?

For typing text on the screen.
For defining a new type of variable.
For making combinations of arrays and records.
For declaring variables of mixed types.

typedef float b;
 ......
b = 3.1;
2. Why doesn't the above code work?

We should use 'typedef b float' instead.
float is already defined.
The syntax is wrong, we should use 'type' instead.
typedef only specifies a type for variables to be declared later and doesn't create a variable itself.

typedef struct {
   struct {
      float x[10];
      int y[3];
    } ri;
    struct {
      float v;
      double w;
    } rd;
  end;
} mystructs[10];

mystructs b;

3. How to assign a value of 0 to a (the first) y of this program?

4. What will be the output of the next code?
typedef float reals[10];

void WriteIt(reals r)
{
  printf("%f\n", r[1]);
}

void main()
{
  int x[10];

  x[1] = 3;
  WriteIt(x);
}

Undetermined. We forgot to initialize the array r!
3.0
Nothing; type mistmatch in calling the function.
3