Question: In C Programming Int40 *kw26Add(Int40 *p, Int40 *q); Description: Return a pointer to a new, dynamically allocated Int40 struct that contains the result of adding

In C Programming

Int40 *kw26Add(Int40 *p, Int40 *q);

Description:

Return a pointer to a new, dynamically allocated Int40 struct that contains the result of adding the 40 digit integers represented by p and q.

Special Notes:

If a NULL pointer is passed to this function, simply return NULL. If any dynamic memory allocation functions fail within this function, also return NULL, but be careful to avoid memory leaks when you do so.

Hint:

Before adding two huge integers, you will want to create an array to store the result. Remember that all integers in this problem are 40 digits long. In the event that the most significant digits (MSD) result in a carry, the carry will be ignored. For example, if the MSD of the two inputs are 9 and 7, the resultant MSD will be 6 with a carry of 1 for the MSD + 1 digit. (916 + 716 = 1016, therefore 6 is the MSD and the 1 is ignored.)1 Returns: A pointer to the newly allocated Int40 struct, or NULL in the special cases mentioned above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!