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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:03:08+00:00 2026-06-02T05:03:08+00:00

If all a function needs to do with a parameter is see its value,

  • 0

If all a function needs to do with a parameter is see its value, shouldn’t you always pass that parameter by constant reference?

A colleague of mine stated that it doesn’t matter for small types, but I disagree.

So is there any advantage to do this:

void function(char const& ch){ //<- const ref
    if (ch == 'a'){
        DoSomething(ch);
    }
    return;
}

over this:

void function(char ch){ //<- value
    if (ch == 'a'){
        DoSomething(ch);
    }
    return;
}

They appear to be the same size to me:

#include <iostream>
#include <cstdlib>

int main(){

    char ch;
    char& chref = ch;

    std::cout << sizeof(ch) << std::endl; //1
    std::cout << sizeof(chref) << std::endl; //1

    return EXIT_SUCCESS;
}

But I do not know if this is always the case.
I believe I’m right, because it does not produce any additional overhead and it is self documenting.
However, I want to ask the community if my reasoning and assumptions are correct?

  • 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-02T05:03:09+00:00Added an answer on June 2, 2026 at 5:03 am

    Even though the sizeof(chref) is the same as sizeof(ch), passing character by reference does take more bytes on most systems: although the standard does not say anything specific about the implementation of references, an address (i.e. a pointer) is regularly passed behind the scenes. With optimization on, it probably would not matter. When you code template functions, items of unknown type that will not be modified should always be passed by const reference.

    As far as small types go, you can pass them by value with a const qualifier to emphasize the point that you aren’t going to touch the argument through the signature of your function:

    void function(const char ch){ //<- value
        if (ch == 'a'){
            DoSomething(ch);
        }
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So all I need is a simple function that sets it up (eating incoming
I need a VBA function that will perform the following: Find all unique values
I'm looking for a tool that will tell/resolve for every function all the call
I've been trying to implement a function that needs partial template specializations and fallen
I need a function to delete all the csv files in a folder A,
I need to replace all System.Environment.Newline(s) in the string returned by my function with
I need to get a stack frame of a function from any PDB (All
I created a header file called ofdm.h which includes all the function prototypes. Then
How can I write (if it's possible at all...) a function which takes an
I want to execute a function on all the objects within a List of

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.