Type Expressions Practice 1
CS16,P. Conrad, UCSB

Together with this problem, there is a program (on a separate handout).

Assuming each of the expressions below appeared in this program, indicate the type they would have, or write error if the expression is not valid, e.g.



The first few are done for you as an example.

Hints--for full credit:

See solution

Expression Type      Expression Type
a double *   i.x        
*b error   i->y  
e     &(j.y)  
b     (*g).x  
&b     (*g)->y  
*a     h.x  
*d     *(h.x)  
e.center     &g  
e->x     argc  
f->y     argv[0]  
e->center->x     argv[0][0]  

Handout for Type Expressions Practice 1

 

Program for question about types

// types.c  Code for exam question, 11/15/2009
// P. Conrad for CS16, 09F, UCSB


#include <stdio.h>
 

struct Point {
  double x;
  double y;
};


struct Date {
  int d;
  int m;
  int y;
};


struct Circle {
  struct Point center;
  double radius;
};


int main(int argc, char *argv[])
{
  double *a;
  double b;
  int *c;
  int d;
  struct Circle *e;
  struct Circle f;
  struct Date *i;
  struct Date j;
  struct Point *g;
  struct Point h;

  // Program does no useful work
  // It is just the basis of a homework assignment about types
// Pretend there is useful code here, and then // answer questions about the types of various expressions // as if they appeared right here. return 0; }