Skip navigation

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.27 (skipped 2.25 & 2.26 since they were qualitative and the answer is the back of the chapter):

Write a function with the following prototype:

/* Determine whether arguments can be added without overflow */
int uadd_ok(unsigned x, unsigned y);

This function should return 1 if arguments x and y can be added without causing
overflow.

Answer:

int uadd_ok (unsigned x, unsigned y) {

  return (x + y) >= x;

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: