Together with this question, 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.
Hints--for full credit:
| Expression | Type | Expression | Type | |
| a | int | f->radius | ||
| &a | int * | f->center.x | ||
| *a | error | f->center->y | ||
| *b | int | &g | ||
| e | struct Circle | *h | ||
| b | &(h->x) | |||
| & b | *(h.y) | |||
| c | i.m | |||
| *c | j.d | |||
| d | i->y | |||
| &d | j->m | |||
| *e | (*j).m | |||
| e.x | argc | |||
| e.radius | argv[0] | |||
| f.y | argv[0][0] |
Program for question about types
// types.c Code for exam question, 11/15/2009
// P. Conrad for CS16, 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[])
{
int a;
int *b;
double c;
double *d;
struct Circle e;
struct Circle *f;
struct Point g;
struct Point *h;
struct Date i;
struct Date *j;
// 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;
}