Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1086211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:47:04+00:00 2026-05-16T22:47:04+00:00

Recently in an interview i was asked a question to write a function which

  • 0

Recently in an interview i was asked a question to write a function which takes two character arrays(integers) as input and returns the output character array.

Function Signature:

char* find_sum(char* a, char* b)

How would one approach this?

Example scenario:

find_sum("12345","32142") = "44487"

Note:

The number of digits can be many(1-100).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:47:05+00:00Added an answer on May 16, 2026 at 10:47 pm

    u can add huge numbers using the char array approach. however you need to delete the char* after using it every time or use some smart pointer.

     char* find_sum(char* a, char* b) {
        int lenA = strlen(a), lenB = strlen(b);
        int max = lenA > lenB ? lenA : lenB; // Get the max for allocation
        char* res = (char*)malloc (max+2);
        memset(res, '0', max +1);      // set the result to all zeros
        res[max+1] = '\0';
        int i=lenA - 1, j = lenB - 1, k = max;
        for (; i >= 0 || j >=0; --i, --j, --k) {
                int sum = 0;
                if (i >= 0 && j>=0)
                        sum = a[i] - '0' + b[j] - '0' + res[k] - '0' ;  // add using carry
                else if (j >= 0)
                        sum =  b[j] - '0' + res[k] - '0' ;     // add the carry with remaining
                else if (i >= 0)
                        sum =  a[i] - '0' + res[k] - '0' ;
                res[k] = sum % 10 + '0';
                res[k-1] = sum / 10 + '0';
        }
        return res;
     }
    
     int main() {
        printf (" sum = %s ", find_sum("12345432409240242342342342234234234", "9934563424242424242423442424234"));
        return 0;
     }
    

    Note: The precondition for the function is the input char arrays should contain only numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was recently asked this question in an interview: There are two arrays of
This question was recently asked to me in an interview for which i went
I recently attended an interview and was asked the following question. There are two
Recently i had an interview in which the question was asked as How would
This is an interview Question that i was asked recently: Write a C program
This is a question I was asked at my interview recently: Which 'Random' object(s)
Here one more basic question asked in MS interview recently class A { public
Recently I was asked this question in an interview. I gave an answer in
Recently I have been asked an interview question What are the events order in
I was recently asked this question in an interview. Lets suppose I have 2000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.