Results 1 to 2 of 2

Thread: Call by Reference or by Value?

  1. #1

    Thread Starter
    New Member Harshjain's Avatar
    Join Date
    Jul 2022

    Call by Reference or by Value?

    I have quite recently started utilizing C++, with a base in C. Having found out about Call by reference, I need to know,if in the following function I found online:

    int insertSorted (int arr [], int n, int ключ, int емкость)
        если (n >= вместимость)
            вернуть н;
        обр[n] = ключ;
        возврат (n+1);
    Please accept my apologies in the event that this question is a piece senseless. I have read a couple of resources on call by value and call by reference in c on wiki and scaler to refresh my understanding and increase my knowledge more on call by value and call by reference in c. Any assistance in clearing up this idea would be perfect.

    Much appreciated.

  2. #2
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014

    Re: Call by Reference or by Value?

    I don't know what question you're trying to ask. arr is passed by value - but arr is effectively a pointer as when an array is passed it is 'decayed' to a pointer. So any changes made in arr in insertSorted() are reflected in the calling function. If you look at the type of arr in insertSorted() then it will of int* - pointer to int. This is the same in C++ and c.
    Last edited by 2kaud; Jul 15th, 2022 at 06:42 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain

    C++23 Compiler: Microsoft VS2022 (17.3.4)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width