Skip to main content
1 vote
1 answer
112 views

Pass mixed references to function: value for small types, and reference for large types

I want to define a templated function that admits parameters by value only when they are "cheap to copy" and by reference when they are not. For example, given function F, the goal is to ...
Lluís Alemany-Puig's user avatar
0 votes
1 answer
70 views

How to assign a new object to a reference?

Why can't I do it like this in Go? func do(m1 map[int]string) { var m map[int]string = make(map[int]string) *m1 = &m; } I have m1 map, which means I can now it's reference? How to assign ...
Pasha's user avatar
  • 1,988
1 vote
2 answers
80 views

Comparing Swift's and Rust's function signatures

I want to check my understanding of how Swift and Rust handle function parameters. From what I’ve seen, Swift has two main parameter modes: Pass by value, immutable: f(x: T) and Pass by reference, ...
Xander's user avatar
  • 11
4 votes
3 answers
212 views

why does getaddrinfo() take the node, service and hints arguments as pointers? [duplicate]

int getaddrinfo(const char *node, // e.g. "www.example.com" or IP const char *service, // e.g. "http" or port number const struct addrinfo *...
SMH_88's user avatar
  • 41
-5 votes
3 answers
113 views

How to fix printing declared function [duplicate]

I'm still new at functions and I tend to print the function which I don't know how to print the declared function. It prints "1" and not "John". #include <iostream> void ...
NAYbabal's user avatar
2 votes
4 answers
107 views

Iterating over an Array

I tried this block of code and it yields two different results public class PassArrayToFunction { public static void increase1(int[] arr){ for(int a: arr) a += 1; } ...
Cường's user avatar
2 votes
3 answers
108 views

Pass "Slice" structs by value or by reference? [closed]

I have the following two structs. They are both "slices" in that they have a pointer to data and dimensions, but they do not "own" the data (they are not responsible for memory ...
StarEgg's user avatar
  • 51
0 votes
2 answers
63 views

Batch function get the value of variable pass by reference

In the below script, there is passed var1 by reference to myDosFunc, so it can change the value. How can the value of the referenced variable be get within the function without having to pass the ...
David Maisonave's user avatar
0 votes
0 answers
51 views

Java Array behaving as call-by-reference only sometimes [duplicate]

I've encountered an interesting issue in Java - I don't know if it's a well known thing (I don't even know what to search for!). Code: public static void main(String[] args) { String[] fruits = {&...
Matt Gray's user avatar
5 votes
1 answer
112 views

Difference on passing a free function as template argument by value or by reference

Consider this code (godbolt): #include <iostream> template<typename F> void call_by_val(F funct) { std::cout << "call_by_val(): "; funct(); } template<...
MatG's user avatar
  • 796
-3 votes
1 answer
95 views

Understanding when a compiler copies, moves or constructs in place [closed]

I've been reading up on copy and move semantics to improve my knowledge of when to use T vs T const & vs T && I wrote a small bit of test code to verify my intuition #include <iostream&...
Sam Coutteau's user avatar
1 vote
2 answers
144 views

Updating a Java Map by different methods

I have a Java Map: Map<String,String> mapThings = new HashMap<>(); updateMapThings(mapThings, sourceMap); // sourceMap is the original Map which has all the ...
user2405589's user avatar
0 votes
0 answers
46 views

If I have a HashMap<String, List<String>> and I want to update a List<String> value, why do I need to put the updated list back into the map? [duplicate]

If I have a Map<String, List<String>> and I want to get the List<String> value for a given key, and then append something to that list, why do I need to call map.put(key, list) to ...
user9174081's user avatar
0 votes
2 answers
53 views

Dart pass by reference or pass by value [duplicate]

I am working on a Dart project and found it confusing about the value assignment for Dart. Before this, I did some research on google which it tells me that the value assignment for Dart is pass by ...
Leong's user avatar
  • 348
0 votes
0 answers
25 views

When passing a pointer to a function in c, what actually happens? [duplicate]

I am trying to learn linked lists. In this I need to use a double pointer to pass by reference. But I am wondering, when we pass a pointer to the function, aren't we sending a copy of the address to ...
Jishnu Prasanth's user avatar

15 30 50 per page
1
2 3 4 5
80