What does the following code write to the monitor?
/* --- rect.h --- */ void setWidth( int w ); void setHeight( int h ); int getArea();
/* --- rect.c --- */ static int width = 0; static int height = 0; void setWidth( int w ) { width = w; } void setHeight( int h ) { height = h; } int getArea() { return height*width; }
/* --- mainRect.c --- */ #include <stdio.h> #include "rect.h" void main() { setHeight( 4 ); setWidth( 3 ); printf("Area: %d\n", getArea() ); }
The header file rect.h is useful so that mainRect.c does not need to have explicitly list all the function prototypes. When you compile from the command line do this (don't list the header file):
prompt>gcc mainRect.c rect.c