

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


void main(void) { int i = 5; f(++i, ++i); } Answer: Thekey pointis that the function arguments can be evaluated in any order. So, the function can be called as f(6, 7) or f(7, 6). So, the two possible outputs are: 6 7 and 7 6
Answer: int add(int a, int b) { /* base case: a == b / if (a == b) return(b); / add lowest element to sum of rest */ return(a + add(a+1, b)); }
x += ++i; Answer: No. The loop has a syntax error, because i++ cannot be assigned to. If the expression in the while condition were i++ <= 100, though, then the program will compile. However, the loop places in x sums the even numbers from 0 to 102, because when i is 100, i++ <= 100 is true (remember, the value of i is used before the โ++โ operator increments i ). c. Does the following for loop do the same thing? If not, what does it do? for(x = i = 0; i <= 100; i++){ if (!(i % 2)) continue; x = x + i; } Answer: No. This sums the odd integers from 0 to 100 inclusive and stores the value in x.
do{ while(s && s != c) s++; if (s) r = s; } while(s++); return(r); } Answer: It returns a pointer to the last occurrence in argument s of the character in argument c. If the character does not occur in that string, it returns the NULL pointer.
void main(void) [ register int c; int counter = 0;
while((c = getchar()) != EOF) if (c == 'a' || c == 'A') a_again(counter);