4,580 questions
1
vote
2
answers
38
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, ...
-1
votes
0
answers
67
views
What is the difference between passing a class pointer by value and by reference? [duplicate]
I am learning C++ and was trying to understand the difference between passing a class pointer by value and by reference.
The program below declares and defines a class named Number. In the main ...
-2
votes
2
answers
184
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 ...
4
votes
3
answers
188
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 *...
-5
votes
3
answers
110
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
0
answers
45
views
PHP foreach loops with references - wierd behaviour [duplicate]
Im currently developing a webpage and during that i wrote some code that looks similar to this:
$foo = ['bar1', 'bar2', "bar3"];
foreach($foo as $i => &$bar){
if($bar == "...
0
votes
2
answers
147
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
2
answers
106
views
Issues passing by reference with gcc. No issues when compiling with gcc
EDIT: Adding this to the top because it is critical information being missed. The FSCC_REGISTERS_INIT call does EXACTLY what it is supposed to do, which is fill the entire struct with '-1's. The ...
2
votes
4
answers
96
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;
}
...
2
votes
3
answers
99
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 ...
0
votes
2
answers
56
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 ...
2
votes
1
answer
35
views
Update items shown in two different views with their own controllers in flutter
I'm new to flutter, and I'm trying to build an application to organize a personal schedule.
I have two views, one for the confirmed events and the other for the non-confirmed ones.
Using calendar_view,...
1
vote
1
answer
57
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{
...
2
votes
1
answer
78
views
How can I pass a file to a function and store the files' contents in an array?
How can I pass a file to a function and store the files' contents in an array?
I have an assignment for a beginner C++ class. The assignment (or at least the part I need help with) is to pass in 2 ...
0
votes
0
answers
50
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 = {&...