Skip to main content
Filter by
Sorted by
Tagged with
-4 votes
0 answers
93 views

While implementing a Dijkstra-Search on a Graph, I call a seperate method to perform the search, handing it a pointer to my nodes and direct values for start/endpoint and array size. Notably,t he ...
Tom Tom's user avatar
1 vote
1 answer
117 views

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
2 votes
2 answers
74 views

I am working on a Python front-end for some existing C++ libraries. As you can imagine, some of the C++ functions use the pass-by-reference method for some arguments. I do not know how to implement ...
Lorenzo's user avatar
  • 180
-2 votes
2 answers
225 views

In a C++ program, I have an API function with the following signature: Foo const & GetFoo() const; The Foo class doesn’t allow copying or moving of instances. The API can’t easily be changed. Now ...
user149408's user avatar
  • 6,269
-5 votes
3 answers
122 views

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
0 votes
2 answers
179 views

#include <stdio.h> void modifyArray(int arr[]) { arr = (int[]){6, 7, 8, 9, 10}; // Trying to modify the array } int main() { int arr[] = {1, 2, 3, 4, 5}; modifyArray(arr); for (...
Alphin Thomas's user avatar
2 votes
4 answers
117 views

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
0 votes
2 answers
71 views

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
1 vote
1 answer
63 views

I'm learning linked lists in C, and have come across an error when trying to add a value at beginning of a linked list using functions #include<stdio.h> #include<stdlib.h> struct node{ ...
Cap_Void's user avatar
0 votes
0 answers
52 views

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
2 votes
3 answers
168 views

Setup I'm taking over code from another person. I found a coding pattern that seems odd to me. This is for an embedded 32 bit PIC processor, in case that's relevant. They have a custom typedef in a ...
Trashman's user avatar
  • 1,665
0 votes
2 answers
105 views

I have these two classes, one inheriting from the other. When an external script calls .copy(), it always receives a parent DataComponent, never a BooleanProperty. If copy() isn't called, a pass-by-...
GeoStorm81's user avatar
-1 votes
1 answer
114 views

In C++ or for any other language, I wish to know that if a function returns a local variable in it's scope to a caller and assigns it to some other variable, how do the semantics work? An example in C+...
uvnarayan's user avatar
1 vote
1 answer
66 views

Today I encountered a behaviour which I did not expect in PHP 8.2. See following code: Code function foo(&$undefined) { if (\is_null($undefined)) { return \sprintf('value: "%s&...
Tintenfisch's user avatar
-1 votes
2 answers
58 views

I need to create a hashmap that stores references to other objects as the values, with the names of those objects as the keys (HashMap<String, Consumer>). The overall system is like a mini-...
Michael Sipos's user avatar
0 votes
1 answer
106 views

I was playing with python to try to reduce memory usage using various methods. One question that arose is if there's a way to pass a list slice as reference to the original list. The reason was the ...
user13079354's user avatar
1 vote
1 answer
229 views

I'm trying to learn the use of std::reference_wrapper and std::ref and the use cases of it. Here is a sample code I wrote. Please help me solve the compilation error. And it would be great if you can ...
Aman Kumar's user avatar
-2 votes
2 answers
148 views

Can we write function in c++, something like this, may be not exactly like this, syntax may be different void FunctionTest(int param1, _Inout_ int& param2 = 10) { param2 = 20; } int main() { ...
user3664223's user avatar
1 vote
2 answers
145 views

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
1 answer
71 views

I was reading Bjarne Stroustrup's "Principle and Practice using C++". In chapter 9.6 about operator overloading, he gives the following example of defining the incrementing operator ++ for ...
a_floating_point's user avatar
0 votes
2 answers
365 views

<?php declare(strict_types=1); class Example { public readonly array $setOne; public readonly array $setTwo; public function __construct() { // Populate $setOne and $...
Tyler V.'s user avatar
  • 2,581
0 votes
0 answers
25 views

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
2 votes
1 answer
71 views

I'm having a concurrency problem when I update an object through an Enum's referenced field. Code here on jdoodle and Github. After setting the object's field, with the method Car#start through ...
kasapkiloet's user avatar
0 votes
2 answers
99 views

void changeName(char* name) { //other action //strcpy(name, "String"); -- this working name = "Marcus"; // -- this not working } int main() { char name[10] ...
Tan Choon Shen's user avatar
0 votes
2 answers
92 views

I was given this hypothetical block of code, where although the language used is Java, and Java uses call by value, in this case call by reference had to be used for every method call, and I had to ...
Ninaaaaa's user avatar

1
2 3 4 5
92