Add, Subtract, and operator[]

In a previous lesson, we encountered a challenge when adding two integers with different lengths. The traditional approach of directly adding the corresponding digits from the two numbers becomes complicated due to mismatched indexing. To address this issue, we adopted a new approach by reversing the order in which we store the digits in an array. By doing so, we achieved a more intuitive indexing system where the unit digit is located at index 0, the 10’s digit is at index 1, and the highest significant digit is at the last index of the array. This reversal of digit order simplifies the addition process and allows for easier handling of numbers with varying lengths.

For example, if we want to add 12341234 (one thousand two hundred thirty-four but stored as 4 3 2 1) to 9898 (ninety-eight but stored as 8 9), we would carry out the following procedure:

Get hands-on with 1200+ tech skills courses.