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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:31:44+00:00 2026-06-01T06:31:44+00:00

Is there a performance benefit by passing ints by reference rather than by value

  • 0
  1. Is there a performance benefit by passing ints by reference rather than by value ? I say this because if you pass by reference you are creating a 4-byte pointer but if you pass by value you are creating a 4-byte copy of the value anyway. So they both occupy an extra 4-bytes, right ?
  2. Is it possible to pass an int literal by reference using a cast: (int *) ? Or do you have to pass a pointer to an int ? See example code below:

    int func1(int *a){
        (*a)++; // edited from comment by Joachim Pileborg
        printf("%i\n", *a);
        return 0;
    }
    
    int func2(int a){
        a++;
        printf("%i\n", a);
        return 0;
    }
    
    int main(void){
        func1(&(int *)5); // an int literal passed by reference using a cast ?
        func2(5);
        return 0;
    }
    
  • 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-01T06:31:46+00:00Added an answer on June 1, 2026 at 6:31 am

    The benefit of passing-by-pointer (there are no references in C) is that a function may update the original int, i.e. return a value in it. There is no performance benefit; rather, passing-by-pointer may slow your program down because the int that is pointed to has to be in addressable memory, so it can’t be in a register.

    Note that &(int *)5 does not do what you think it does. (int *)5 casts the value 5 to a pointer, interpreting it as a memory address. The & would give that pointer’s address, except that taking the address of a temporary is illegal. You probably meant

    int i = 5;
    func1(&i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested to find out if there is a performance benefit to partitioning a
Given the following two code options, is there any performance benefit (over a very
Are there any performance benefits to be gained from passing objects like WebControls by
Is there any performance benefit in configuring web gardens in IIS? Anyone have any
Possible Duplicate: Is there a performance benefit single quote vs double quote in php?
Is there a performance benefit to removing OR statements? Which compiles faster SELECT id
Is there any performance benefit to using const or readonly fields compared to regular,
I've seen a lot of people do the former, is there any performance benefit
Is there a performance benefit of having variables dimensioned in the beginning of a
Is there any performance benefit to pre-compiling an asp.net web application if it's set

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.