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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:50:41+00:00 2026-06-11T00:50:41+00:00

I am new to C, and I have to make a mini calculator program

  • 0

I am new to C, and I have to make a mini calculator program (this is homework, but I’m not looking for the answer, just a little more understanding). Basically, one function must look like this:

int add(double d, double dd, double *result);

It will return a 0 if there are no errors, and -1 if an error occurred (in the case of addition, there wouldn’t be many errors – but division for example, divide by 0 would be an error).

A user has to input two numbers into the terminal, those numbers then get used as the parameter values in the add method. What I don’t understand is what is result initially when the method is called? Is it just null? And why would I want to return 0 or -1 and not result instead? For example:

double result;
returnValue = add(2.0, 5.0, &result); 

Obviously I’ll get 7 as the result, but how will I print that out without returning the result? returnValue is 0, so I know there were no errors, so now I need to print result.

  • 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-11T00:50:44+00:00Added an answer on June 11, 2026 at 12:50 am

    C doesn’t have pass by reference. You can pass in a pointer, which is what you’re doing here, but C only has pass by value.

    Now to your actual questions:

    What I don’t understand is what is result initially when the method is called? Is it just null?

    No, the value of result is undefined before the add function is called. You have no guarantees whatsoever if you try to use the value of result before assigning to it, either by assigning to it in the function where it’s declared or by assigning to it in add with code like *result = d + dd.

    For that matter, a double can never be null. Null is a possible pointer value, not a possible floating-point number.

    And why would I want to return 0 or -1 and not result instead?

    If you were to return result directly, you’d have to have some kind of distinguished “calculation failed” return value, which is kind of messy and leaves the caller to check the result before using it. This way forces the caller of add to notice that there is status code as the return value, and if the caller wants to ignore it then they can (although you shouldn’t ignore status codes).

    Obviously I’ll get 7 as the result, but how will I print that out without returning the result?

    Ed Heal is right to suggest printf. If you’re using Linux or Mac OS X, though, I’d also recommend running man printf from the terminal – it’s often more convenient than opening a web browser.

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

Sidebar

Related Questions

see i have make one program which create one new file just using fopen()
I am very new to this and have used the Qt Designer to make
I have this anonymous type : var t= new {a=1,b=lalala,c=DateTime.Now}; How can I make
I am new in java. I try to make a program and I have
I have make 1 animation in cocos2d game, but not able to see that
I have make a new dropdown navi in css . Chrome, firefox, safari is
see fiddle Firstly i am new to jquery. i have to make one cell
I have created a file with XmlDocument xmldoc = new XmlDocument(); Can I make
I have a problem with datePicker. When a make a new text field with
I have make a little Extension for Magento 1.6.2. I managed to write code

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.