Questions tagged [pass-by-value]

pass-by-value is a "one way passing" so that modifications of the passed value inside the receiving function (or other entity like process, etc) are not returned back.

pass-by-value is a one way passing so that modifications of the passed value inside the receiving function (or other entity like process, etc) are not returned back.

pass-by-value normally means cloning a variable and making a cloned copy available to the receiving function. Modifications of this copy are allowed, but they are not returned back to the caller; the copy is simply disposed after the call returns.

Passing by value is more secure if the function can also be called by malicious code (malicious code can retain the reference and observe it later even if it cannot modify it). Some are also convinced it results a cleaner code. However passing of the larger structures by value also requires more resources.

1173 questions
-3
votes
4 answers

C, pass by value, in Linux

I have a function as follows: void foo (int *check){ *check= 9; printf("*check: %d\n",*check); //when I print "*check" here, the value changes as 9. } This is the main function. void main () { int check=5; foo(&check); printf("check:…
helloword
  • 5
  • 2
-3
votes
1 answer

How to pass a [][]int variable

We know Go is pass by value, and the slice is pointer type, then what about the [][]int? I got this code func add(nums [][]int) { nums = append(nums, []int{1,2,3}) } It seems the nums doesn't change after this function. I got confused about the…
S.Ye
  • 57
  • 2
  • 6
-3
votes
5 answers

How to swap integers without using pointers?

#include int swap(int a,int b); int main() { int x,y; printf("Enter the first integer:"); scanf("%d",&x); printf("Enter the second integer:"); scanf("%d",&y); printf("\nBefore swap: x=%d, y=%d\n",x,y); swap(x,y); …
-3
votes
2 answers

Is Python similar to the -> operator in C/C++?

So in Python you can do the following: def append(_list): _list.append(1) _list = [0] append(_list) print(_list) This obviously allows me to append 1 to the list, however if I change the reference of list within the append function it doesn't…
DJ Poland
  • 955
  • 1
  • 9
  • 23
-3
votes
1 answer

Issues converting istream to ifstream while passing std::cin into an argument

I am currently implementing a text-file based testing UI that will take mocked up user inputs from a text file (line-by-line) to simulate real user input instead of using std::cin. The issue arises when I attempt to pass std::cin into std::ifstream…
-3
votes
1 answer

c++ Passing var from function to function then display result in main function

How do I pass the user entered distance gathered from one function to another function to calculate a shipping cost? And then show the cost via the int main function? My distance function double getDistance(double distance) { cout << "Enter the…
Meno
  • 1
  • 3
-3
votes
2 answers

C - function parameters and pointers

Consider two cases of calling a function: void Convert(int number, int **staticPointer) { int * dynamicPointer = malloc(sizeof(int)); *dynamicPointer = number; *staticPointer = dynamicPointer; } int main() { int *p; Convert(5,…
Pavoo
  • 75
  • 2
  • 6
-3
votes
2 answers

How to print an array from one method to another?

I need a way to print 3 these arrays... public static void viewCatalog(){ String[] description = new String[15]; description[0]= "Alumni Drink ware"; description[1]= "Binders"; description[2]= "Bookbag"; description[3]= "Fabulous…
Allie Carroll
  • 9
  • 1
  • 1
  • 3
-3
votes
1 answer

What is the value of 'x' for each scenario?

I have the following C-like program, and I'm trying to figure out the final value of array x for when: Argument x is passed by value. Argument x is passed by reference. Argument x is passed by value-result. CODE: void swap(int[] list, int i, int…
Analytic Lunatic
  • 3,853
  • 22
  • 78
  • 120
-3
votes
1 answer

Converting this code to Method Version

i have trouble with my java project homework. in this program when i use case 1 it activates student recording system. i need i must write all of this recording system with method. i tried but i failed. can you show me how can i write method…
Gökhan Nas
  • 45
  • 2
  • 8
-4
votes
1 answer

Are arrays passed by reference or value in PHP?

Are arrays passed by reference or value in PHP? For example, let's see this code. function addWeight($arout, $lineCountry, $lineDomain, $target, $weight) { $currentDomain=getDomain(); $currentCountry=getCountry(); if…
user4951
  • 32,206
  • 53
  • 172
  • 282
-4
votes
2 answers

jQuery get the value dropdown and pass it to the second dropdown

I've the following scenario: There is on the homepage a dropdown with some options. On a detailpage there is the same dropdown. What I want is when the user selects one of the dropdown options, the page redirects to the "detail" page with the same…
BlueBay
  • 67
  • 2
  • 9
-4
votes
4 answers

C passing and pointers

So I'm writing this program, and I do not know how to pass by reference or value. I just need to pass for values from one function (processFile) to another function (printReport). Any help on how to do this would be appreciated. #include…
-5
votes
3 answers

Java is Pass-By-Value and Pass-By-Reference Both

Possible Duplicate: Is Java pass by reference? Let me know the answer soon Please!!!
JavaSun
  • 58
  • 7
-5
votes
2 answers

Why doesn't this return a new value over and over? java

public static int someFunc(int a, int b){ while(a <=b){ a+= 1; return a; } return b; } so i was expecting it to return the new value over and over but it didnt, once i executed the code and saw for myself that, i…
Reddevil
  • 125
  • 3
  • 12
1 2 3
78
79