Part 1: The following code fragment produces the correct result sometimes and sometimes does not. Explain what is happening and why.
#include
#define max(a,b) ((a) > (b) ? (a): (b))
int main(void)
{
int i = 0;
int j = 0;
int a = 3;
int b = 4;
int c = 6;
int d = 5;
i = max(a,b); //4
j = max(c,d);//6
printf("i = %i, j = %i\n",i,j);//4 6
i = max(a++, b++);//6
printf("a = %i, b = %i\n",a,b);//4 5
j = max(c++,d++);//6
printf("c = %i, d=%i\n",c,d);//7 6
getch();
return;
}
Part 2: In the C language, the struct cannot hold function members; thus, we include functions by using pointers to functions. Combining data and the functions that operate on that data can be a very powerful tool in developing embedded applications. (a) Give the class diagrams for three structures. The three structures will share a common data variable called sharedData through pointers to that data. The three functions will be getData(), compute(), and outputData(). The function getData() will bring data into the system, compute() will multiply the data by 2, and outputData() will send the data out of the system. (b) Give the data and control flow diagrams for such a system.
Excellent Solution
================
*Instant Download
The following code fragment produces the correct result sometimes and sometimes does not
- Technology: C-Programming
- Code: SHC_C_100011
-
$9.99
Tags: c, programming, struct, function, pointers to functions, sharedData, getData(), compute(), outputData()