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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:44:06+00:00 2026-06-12T04:44:06+00:00

Possible Duplicate: How to modify content of the original variable which is passed by

  • 0

Possible Duplicate:
How to modify content of the original variable which is passed by value?

I am building a pretty simple program that calculates the area of a rectangle. Simple enough however, as you will notice I cannot seem to get a return value. I keep seeing 0. There is probably an obvious answer or perhaps there is something I just don’t understand. Heres my code:

#include<stdio.h>

//prototypes
int FindArea(int , int , int);

main()
{

//Area of a Rectangle

  int rBase,rHeight,rArea = 0;

  //get base
  printf("\n\n\tThis program will calculate the Area of a rectangle.");
  printf("\n\n\tFirst, enter a value of the base of a rectangle:");
  scanf(" %d" , &rBase);

  //refresh and get height
  system("cls");
  printf("\n\n\tNow please enter the height of the same rectangle:");
  scanf(" %d" , &rHeight);

  //refresh and show output
  system("cls");
  FindArea (rArea , rBase , rHeight);
  printf("\n\n\tThe area of this rectangle is %d" , rArea);
  getch();

}//end main

int FindArea (rArea , rBase , rHeight)
{
 rArea = (rBase * rHeight);

 return (rArea);

}//end FindArea
  • 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-12T04:44:07+00:00Added an answer on June 12, 2026 at 4:44 am

    You intialize rArea to 0. Then, you pass it into FindArea by value. This means none of the changes to rArea in the function are reflected. You don’t make use of the return value, either. Therefore, rArea stays 0.

    Option 1 – Use the return value:

    int FindArea(int rBase, int rHeight) {
        return rBase * rHeight;
    }
    
    rArea = FindArea(rBase, rHeight);
    

    Option 2 – Pass by reference:

    void FindArea(int *rArea, int rBase, int rHeight) {
        *rArea = rBase * rHeight;
    }
    
    FindArea(&rArea, rBase, rHeight);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Modify Struct variable in a Dictionary Why is it that MyStruct test
Possible Duplicate: Detect element content changes with jQuery I am trying to modify the
Possible Duplicate: Is Java pass by reference? I need to modify the content of
Possible Duplicate: Modify the URL without reloading the page I'm looking for a way
Possible Duplicate: Modify the URL without reloading the page I know the subject is
Possible Duplicate: uninitialized const I understand that a const object needs to initialized. So
Possible Duplicate: Is there any reason to modify the main.m file in your iOS
Possible Duplicate: Most efficient method to get key for a value in a dict
Possible Duplicate: Can I use a generated variable name in PHP? Am stuck here!
Possible Duplicate: getting segmentation fault in a small c program Here's my code: char

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.