#include <stdio.h> struct Bulb { int watts; int lumens; }; /* function to print a Bulb */ void printBulb( struct Bulb* b ) { printf("watts = %d\tlumens = %d\n", b->watts, b->lumens ); } /* function to decrease light output */ void dimBulb( struct Bulb* b ) { /* decrease output by 10 percent */ b->lumens = (b->lumens*90)/100; } int main(int argc, char *argv[]) { struct Bulb bulbA = {100, 1710 }; printBulb( &bulbA ); dimBulb( &bulbA ); printBulb( &bulbA ); system("pause"); return 0; }
Comments:
The parameter for dimBulb()
must be an address
if the function is to make a permanent change to the data in main()
's bulbA
.