4,581 questions
-4
votes
0
answers
93
views
SIGSEV signal after method call - How do pointers work after pass-by-reference?
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 ...
1
vote
1
answer
117
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 ...
2
votes
2
answers
74
views
How to pass args by reference in python scripts using cppyy?
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 ...
-2
votes
2
answers
225
views
Optional const by-reference argument in C++
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 ...
-5
votes
3
answers
122
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 ...
0
votes
2
answers
179
views
Why does this function not modify the original array when passed as a parameter?
#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 (...
2
votes
4
answers
117
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;
}
...
0
votes
2
answers
71
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 ...
1
vote
1
answer
63
views
Error in using call by reference with function to change the head of a singly linked list
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{
...
0
votes
0
answers
52
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 = {&...
2
votes
3
answers
168
views
Why pass void pointer instead of custom type?
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 ...
0
votes
2
answers
105
views
'new' keyword returning the same instance of a class
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-...
-1
votes
1
answer
114
views
Function return value and assignment in C++ [duplicate]
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+...
1
vote
1
answer
66
views
Why can I pass a non-existent variable by reference? [duplicate]
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&...
-1
votes
2
answers
58
views
Creating Hashmap for Storing References as Values for Pub-Sub
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-...
0
votes
1
answer
106
views
Is it possible to pass a python list slice as reference? [duplicate]
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 ...
1
vote
1
answer
229
views
How do I use std::reference_wrapper to store the reference in an std::unordered_map?
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 ...
-2
votes
2
answers
148
views
Is it possible in C++ passing function inout parameter with default value
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() {
...
1
vote
2
answers
145
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
...
0
votes
1
answer
71
views
Why return the Month object from this operator overloader function?
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 ...
0
votes
2
answers
365
views
PHP Readonly properties can't be passed by reference?
<?php
declare(strict_types=1);
class Example {
public readonly array $setOne;
public readonly array $setTwo;
public function __construct()
{
// Populate $setOne and $...
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 ...
2
votes
1
answer
71
views
Java concurrency problem with enums and references
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 ...
0
votes
2
answers
99
views
Why cant I modified the char array when passing it as an argument to the function and assigning it a new value?
void changeName(char* name) {
//other action
//strcpy(name, "String"); -- this working
name = "Marcus"; // -- this not working
}
int main() {
char name[10] ...
0
votes
2
answers
92
views
Call by reference confusion
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 ...