programing in C the book problem solving and program desig
programing in C ( the book / problem solving and program design in C )
1. What is the output of the following program segment?
void myFunc(double *y);
int main(void) {
double a = 10.5;
double b = 11.5;
printf(\"a = %d\ \", a);
myFunc(&a);
printf(\"a = %d\ \", a);
printf(\"b = %d\ \", b);
myFunc(b);
printf(\"b = %d\ \", b);
return 0;
}
void myFunc(double *y) {
*y = *y + 10;
}
2. Which of the functions in the following program outline can call the function grumpy? All function prototypes and declarations are shown; only executable statements are omitted.
int grumpy(int dopey);
char silly(double grumpy);
double happy(int goofy, char greedy);
int main(void) {
double p, q, r;
...
}
int grumpy(int dopey) {
double grumpy_value;
...
}
char silly(double grumpy) {
double silly_value;
...
}
double happy(int goofy, char greedy) {
char happy_value;
...
}
3. draw the data areas of functions main and myFunc as they appear immediately before the return from the first call to myFunc in Q1. The figure format and notation should look like Fig 3.8, Fig 6.11 in the textbook.
Solution
1. Compile time error
void myFunc(double *y);
int main(void) {
    double a = 10.5;
    double b = 11.5;
    printf(\"a = %d\ \", a); // output: 10 (integer part of 10.5)
    myFunc(&a);
    printf(\"a = %d\ \", a); // output: 20 (integer part of 20.5)
    printf(\"b = %d\ \", b); // output: 11 (integer part of 11.5)
    myFunc(b); // error: myFunc takes adress of double variable, but here we are passing value os b
    printf(\"b = %d\ \", b);
    return 0;
 }
void myFunc(double *y) {
    *y = *y + 10;
 }
2)
\'happy\' function can call grumpy function because \'grumpy\' takes an int as argument and \'happy\' has a int parameter
int grumpy(int dopey);
char silly(double grumpy);
double happy(int goofy, char greedy);
int main(void) {
    double p, q, r;
    ...
 }
 int grumpy(int dopey) {
    double grumpy_value;
    ...
 }
char silly(double grumpy) {
    double silly_value;
    ...
 }
double happy(int goofy, char greedy) {
    char happy_value;
   // can call grumpy
    int grumpy_value = grumpy(goofy);
   
    ...
 }
I have answered first 2 questions. Please post last in separate post.
Please let me know in csae of any issue.



