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

  • Home
  • SEARCH
  • 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 3978148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:00:38+00:00 2026-05-20T05:00:38+00:00

Yesterday on an interview the interviewer asked me a question: Why doesn’t the following

  • 0

Yesterday on an interview the interviewer asked me a question:

Why doesn’t the following code give the desired answer?

int a = 100000, b = 100000;

long int c = a * b ;

The language is C.

I’ve told the interviewer that we count first the 100,000 * 100,000 as an int(overflow) and just then cast it to long.

  • 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-20T05:00:39+00:00Added an answer on May 20, 2026 at 5:00 am

    I’m guessing the clue would be an integer overflow to occur, but with such low values, I don’t see that happening.

    Maximum (positive) value for int (usually 32bit) is: 2,147,483,647

    The result of your calculation is: 100,000,000

    UPDATE:

    With your updated question: 100000 * 100000 instead of 10000 * 10000 results in 10,000,000,000, which will cause an overflow to occur. This value is then cast to a long afterwards.

    To prevent such an overflow the correct approach would be to cast one of the two values in the multiplication to a long (usually 64bit). E.g. (long)100000 * 100000

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

Sidebar

Related Questions

I had telephone interview question yesterday. The interviewer asked me if I had faced
Yesterday, I asked this question and never really got an answer I was really
this is an interview question my friend was asked yesterday. The question was something
Yesterday in my interview I was asked this question. (At that time I was
Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis)
Yesterday i had a question in an interview which i thought i could find
Was asked in an interview yesterday to name three good and three bad things
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
Yesterday, I have a discussion with my colleagues about HTTP. It is asked why
I got this question today in an interview: write a function to calculate the

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.