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 8814207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:03:21+00:00 2026-06-14T04:03:21+00:00

This is the sample code of my program, in which i’ve to add two

  • 0

This is the sample code of my program, in which i’ve to add two string type integer (ex: "23568" and "23674"). So, i was trying with single char addition.

char first ='2';
char second ='1';

i was trying like this..

i=((int)first)+((int)second);
printf("%d",i);

and i’m getting output 99, because, it’s adding the ASCII value of both. Anyone please suggest me, what should be the approach to add the char type number in C.

  • 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-06-14T04:03:22+00:00Added an answer on June 14, 2026 at 4:03 am

    Since your example has two single chars being added together, you can be confident knowing two things

    1. The total will never be more than 18.
    2. You can avoid any conversions via library calls entirely. The standard requires that ‘0’ through ‘9’ be sequential (in fact it is the only character sequence that is mandated by the standard).

    Therefore;

    char a = '2';
    char b = '3';
    
    int i = (int)(a-'0') + (int)(b-'0');
    

    will always work. Even in EBCDIC (and if you don’t know what that is, consider yourself lucky).

    If your intention is to actually add two numbers of multiple digits each currently in string form (“12345”, “54321”) then strtol() is your best alternative.

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

Sidebar

Related Questions

I'm trying to make my program read/write in a database. I found this sample
I have created the fallowing Sample-Code: class Program { static void Main(string[] args) {
Im trying to write a simple sample program which checks for any new mail
Following is a sample code from my program which queries the database and results
In this sample code the URL of the app seems to be determined by
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
A friend show me this sample code to implement HTTP POST in C# and
I have this sample code: DirectoryEntry _entry = new DirectoryEntry( connectionString, this.userPrinicipalName, this.password, AuthenticationTypes.SecureSocketsLayer
I have this sample code for async operations (copied from the interwebs) public class
Say I have this sample code I'm writing for a Python lesson I'm holding:

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.