Skip to main content

All Questions

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 *...
SMH_88's user avatar
  • 41
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 (...
Alphin Thomas's user avatar
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 ...
firstName lastName's user avatar
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 = {&...
Matt Gray's user avatar
0 votes
2 answers
83 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] ...
Tan Choon Shen's user avatar
0 votes
1 answer
55 views

C Array elements all changing to the same value

I'm trying to populate an array of names using an input file, however the elements of my array all end up turning into the same value and I'm unsure why. char* names[name_count]; for (int i = ...
Grekys's user avatar
  • 41
0 votes
2 answers
186 views

const int * is incompatible with const int (*)[10]

I am trying to understand why the following code does not work: void printArray(const int(*array)[10]) { cout << sizeof(array) << endl; } int main() { const int arr[10] = { 1, 2 };...
SAQ's user avatar
  • 131
-1 votes
3 answers
163 views

my C function is modifying a char array it shouldn't because it's deliberately out of scope

I wrote a little program in C that checks if a word of phrase is a palindrome. One function does the checking after calling another function to remove the spaces in a phrase. The app first asks the ...
Charles H's user avatar
-2 votes
1 answer
167 views

Array passed by reference is not updated in C++ [closed]

I'm trying to pass an array to a C++ class, in order the make the changes to the array objects visible outside the class. But it is not working. The changes to the Motor objects are lost after every ...
BetaRide's user avatar
  • 17k
0 votes
2 answers
147 views

Struct passed by value is modified in function in c

I have this code were i need to sort an array of struct without modifying it. I passed the array of struct by value and i used an int array with indexes to sort the struct. To sort the array i also ...
th3 wolf's user avatar
1 vote
1 answer
93 views

How are updates to var arrays handled in Swift memory (confused about CoW)

I have this function to do a quick select partition when sorting numbers in descending order. The function refers to arr defined outside its scope (partition is a nested func in another func). My ...
Dracula's user avatar
  • 3,100
0 votes
1 answer
83 views

Symfony ObjectProphecy treats array and object differently - can't change array which was initialised in setUp method

Related to this I am trying out this test code <?php use Monolog\Test\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophet; class MyBar { public int $bar = 0; } class MyFoo { ...
user_51's user avatar
0 votes
1 answer
122 views

Add value to array in Symfony TestCase class in test function if the array was initialised in setUp method

Apologies if the question looks off, I am new to both Stack Overflow and php. My class looks a bit like this: final class MyClass extends TestCase { private MyService $myService; private ...
user_51's user avatar
0 votes
2 answers
109 views

how to use sizeof() for reference_to_array in c++ [duplicate]

How to use sizeof() to determine the size of a reference to an array? I have declared an array in main() and used sizeof() to print its total size it has occupied. And then I pass the array to a ...
semicolon_missing's user avatar
0 votes
0 answers
32 views

How to avoid passing by reference inside of method (Java)? [duplicate]

I'm making my own Java matrix program for a linear algebra class and can't seem to stop passing my arrays by reference. I want each method to return a matrix (thus performing calculations based on the ...
Aidan K's user avatar

15 30 50 per page
1
2 3 4 5
31