Questions tagged [call-by-value]

Evaluation that bounds the resulting value to the corresponding variable in the function (frequently copying the value into a new memory region).

95 questions
0
votes
6 answers

Rearrange order of an ArrayList

I want to rearrange an ArrayList by iterating through it and copying each element to a specific place in a new list. In this case I want to move an element to the end of the list. For example, if the list is ABCDE and j == B then the new list should…
ArtVandelay
  • 97
  • 3
  • 11
0
votes
3 answers

C Code: Passing expression as an argument in recursion call

I am practicing some C questions came across a scenario where a recursive function calls itself with an expression as an argument. Pow(double x, unsigned n){ ..... ..... return Pow(x*x,n/2); } My question is whether the arguments are passed…
0
votes
1 answer

Why am I getting same value (0x7fff5fbff808) as output while passing vl or vl1? The address should be different

void ShowValue(int **value) { std::cout<<"Value 0 = "<<**value<<"\t"<<*value<<"\t"<
0
votes
5 answers

How is passing a string literal to a function handled in C++?

Consider the following piece of code: void consumeString(std::string str){ /* some code */ } void passStringObject(){ std::string stringObject = "string literal"; consumeString(stringObject); } void passStringLiteral(){ …
0
votes
2 answers

Call-By-Value vs Call-By-Reference revisited

let me first say. I know the title suspects that I'm asking a question which was answered here and around the internet many times. I did research indeed yet I just can't find a satisfying answer. My question in the end comes down to this. Why is…
ben
  • 5,671
  • 4
  • 27
  • 55
0
votes
3 answers

How to do this program in C? Part 3.2-3.9

Are multiple conditions, as in multiple if else statements needed for the intersection rectangles to be printed correctly? Step 3: Two rectangles intersect if they have an area in common Two rectangles do not overlap if they just touch (common edge,…
user2805620
  • 125
  • 1
  • 1
  • 13
0
votes
3 answers

Modifying object collections

I'm working in some Java code and I have a doubt. I have a loop that goes along a Collection to modify each one of its objects with a method. The thing is, when you pass an object to a method, what are you really passing? A copy of the reference?…
Hannibaal
  • 97
  • 1
  • 7
-1
votes
3 answers

which part of the memory does the result of the expression of the return statements gets stored in?

the case is int func(void){ int A = 10; int B = 20; return A+B } which is being called by the main function int main(void){ int retVal = func(); return 0; } in the function func() two local variables will be…
aTechieSmile
  • 139
  • 1
  • 1
  • 11
-1
votes
2 answers

Swap elements of two structures

I have simplified my question to this small C program. Please note that I am learning C on my own. I a having real trouble with pointers! #include #include typedef struct Elmt_ { int *i; struct Elmt_ *next; } E; void…
noobee
  • 57
  • 3
-1
votes
1 answer

Unable to pass 2-Dimensional array while using recursion in c++

I saw an answer in stackoverflow regarding how to pass a 2d-array in a function there are 3 or more methods given when I tried one of them it worked just fine. But when I'm trying to use that method in backtracking it is giving me an error. I…
-1
votes
1 answer

Two cases which should avoid calling copy constructor

I have learned about three cases about calling the copy constructor 1. A variable is being initialized from an object of the same class 2. A function is called with a value parameter of the class 3. A function is returning a value that is an object…
cp3
  • 1
  • 2
  • 7
-1
votes
1 answer

Call by Reference or by Value?

I have just begun using C++, with a base in C. Having learned about Call by reference, I need to know,if in the following function I found online: int insertSorted(int arr[], int n, int key, int capacity) { if (n >= capacity) return n; …
-1
votes
2 answers

Java call by value

I realize this is a commonly asked question, but here it is .. I tried to write this to figure out how Java handles parameter passing and so on.. public class CallByValue { int key; public void changeValue(CallByValue c){ …
user3386479
  • 51
  • 2
  • 8
-2
votes
1 answer

C# changing previously assigned values

I have a function that gets called on a two dimensional array "a" and alters the array. However, it also alters any array that was previously assigned to "a", before even calling the function. I'm not sure if I understand why! char[][] copy; copy =…
Nila
  • 1
  • 4
-2
votes
5 answers

anything like pointers in c#?

I'm new to c# (& coding in general) and i can't find anything pointer equivalent. When i searched google i got something like safe/unsafe but that's not what i needed. Like in c++ if you had a pointer and it pointed towards some value, the change in…