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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:43:32+00:00 2026-06-14T00:43:32+00:00

If I pass an int it will be passed by value. void something(int i)

  • 0

If I pass an int it will be passed by value.
void something(int i)
If I pass some type of array it will be passed by reference.
void something(int i[])
OR
void something(int *i);

Types like int will be passed by value, arrays will be passed as reference.

The first question is, are there any more types that will be passed by reference?
The second question is, what is the difference between the first pass of the array (int i[]) and the second one (int *i) ?

EDIT:
I will clarify my question.
Which other types that you pass to a function, such as arrays, will be changeable inside the function. (which is not exactly pass-by-ref, as you explained).

void something(int i[])
{
i[0]=5;
}

something(i);

This will change the array not only locally.

What about structs? unions? A pointer to them passes too?

  • 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-14T00:43:33+00:00Added an answer on June 14, 2026 at 12:43 am

    Everything is passed by value, period.

    The difference is in how C treats array expressions. Except when it is the operand of the sizeof, _Alignof, or unary & operators, or is a string literal being used to initialize another array in a declaration, an expression of type “N-element array of T” will be converted (“decay”) to an expression of type “pointer to T“, and the value of the expression will be the address of the first element of the array.

    So given a declaration like

    int a[10] = {0};
    

    whenever the expression a appears anywhere in your code other than &a, sizeof a, or _Alignof a, it will be converted to a pointer expression and the value of the expression will be the address of a[0], regardless of whether the expression is being passed to a function or not.

    So in a function call like

    foo(a);
    

    the expression a is converted to a pointer expression, and the value of the pointer expression (&a[0]) is passed to the function.

    Similarly, in a function parameter declaration, T a[] and T a[N] are interpreted as T *a; the parameter is being declared as a pointer, not an array, regardless of the array notation.

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

Sidebar

Related Questions

I'm trying to pass an Int value pulled from a JSON String to reduce
I have a UISplitViewController in which i'm attempting to pass an int value from
i had a question in my program. When I pass the 3D int array
im trying to pass two parameters to a function, i being an int value
I would like to pass a pointer by reference to a function, such that
Possible Duplicate: C# - Reference type still needs pass by ref? class OutReturnExample {
How does C/C++ deal if you pass an int as a parameter into a
I have a testdata like this: DROP TABLE SELECT_PASS; CREATE TABLE SELECT_PASS(ID INT(20),TESTCASE VARCHAR(20),RESULT
I want to pass 2 variables: UIImage * img int i into another method
Can i pass strings as arguments during method.Invoke(objectname,object[]params) for a method of signature Getdetails(int,string,bool)

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.