SSL Certificate
  • The following code fragment produces the correct result sometimes and sometimes does not
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

Write a review

Please login or register to review

The following code fragment produces the correct result sometimes and sometimes does not

  • $9.99


*All your data are SECURED & ENCRYPTED using a valid, trusted server certificate (Comodo SSL) and we don't store credit card information on our servers and all Payments are SECURED & handled by Paypal.
SSL CertificatePaypal

Tags: c, programming, struct, function, pointers to functions, sharedData, getData(), compute(), outputData()