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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:02:33+00:00 2026-05-24T05:02:33+00:00

Here I have written some code to get the square of a number from

  • 0

Here I have written some code to get the square of a number from a function, but the return statement is not working as desired by me, it is giving me the same number which I have entered, I want to know the reason behind this, please if any one can explain this to me…

#include<iostream>
#include<conio.h>

using namespace std;
int square(int &i);

int main()
{
    cout<<"enter the number whose square you want to find";
    int a;
    cin>>a;
    square(a);

    cout<<"the square of the number is"<<a;
    _getch();
    return 0;
}

int square(int &i)
{
    return i*i;
}
  • 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-24T05:02:34+00:00Added an answer on May 24, 2026 at 5:02 am

    You do not obtain the result.
    Your line should be:
    a = square(a);
    to fetch the result from the function.
    The other possibility would be to write in the function

    int square(int &i)
    {
        i = i * i;
        return i;
    }
    

    The latter will alter the variable you passed to the function which justifies passing a reference.


    To make it clear you want to alter the variable do something like:

    void square(int &i)
    {
        i = i * i;
    }
    

    You see there is no return involved but it will alter the variables value.

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

Sidebar

Related Questions

lets get straight to my problem, the code I have written here does not
Here's a snippet of code from a shell script I have written: for src
I have written a php code which will get one id from database and
JAVA Code Here is some part of my code that I have written in
can anyone help me? I have some reflection code that i have written and
Just wondering what little scripts/programs people here have written that helps one with his
Here's the thing: I have two applications, written in C++ and running on two
The system I work on here was written before .net 2.0 and didn't have
Around here we have been working with a bunch of Visual Source Safe repositories
I have written a program to process some data written to disk in big-endian

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.