Questions tagged [pass-by-pointer]

Pass-by-pointer is a concept (commonly used in C or C++) that refers to passing the address (pointer) of a variable to a function.

Pass-by-pointer is a concept (commonly used in C or C++) that refers to passing the address (pointer) of a variable to a function.

Example:

void swap(int *a, int *b)

Without pass-by-pointer, swap would not be able to swap the contents of the two passed-in variables.

101 questions
4
votes
1 answer

How to pass by reference in Ruby?

Currently I'm developing a Watcher class in Ruby, which, among other things, is able to find the period duration of a toggling signal. This is in general rather simple, but a problem I'm facing is that apparently Ruby passes all parameters by…
4
votes
2 answers

Why do I have to pass a pointer to a pointer in this case

This question is builds on a previous question from me. There I had this construct. It uses SDL2: void init_window(SDL_Window *window) { window = SDL_CreateWindow(…); } int main(void) { SDL_Window *window; init_window(window); } This…
hgiesel
  • 5,430
  • 2
  • 29
  • 56
4
votes
6 answers

passing a pointer to a built-in type defined on the fly in c++

I want to call a function of a library (that I can not modify) void function(int* i, char* c); Is there a way to call the function defining the int and the char on the fly? i.e. doing something like function(&1, &'v'); instead of int int_1 =…
dPol
  • 455
  • 4
  • 14
3
votes
3 answers

Pass subarray by reference (not by value) in Common Lisp

Let's suppose I have an array - which I will call *my-array* - that looks like this: #2A((1 2 3) (4 5 6) (7 8 9)) and I wish to apply some function f on the subarray #2A((5 6) (8 9)) I'd love to be able to write (f (subarray…
3
votes
4 answers

C++ Call by reference

If I have a function which takes a pointer to an integer, and I pass a reference to an integer variable from my main, is this call by value or call by reference? Sample code: #include using namespace std; void fun(int *a){ //Code…
2
votes
2 answers

Segfault when passing structure from main() to worker functions

I am trying to write a simple game in C and I'm getting a SEGFAULT and have no idea why! Here is the code for the program: #include #include #define MAX_PLYS_PER_GAME (1024) #define MAX_LEN (100) typedef struct { char…
2
votes
2 answers

Returning an object: value, pointer and reference

I know this has probably been asked and I've looked through other answers, but still I cannot get this completely. I want to understand the difference between the two following codes: MyClass getClass(){ return MyClass(); } and MyClass*…
Harnak
  • 225
  • 1
  • 3
  • 12
2
votes
1 answer

Inout parameters don't have the same address

I have three classes A, B and C. A has a resource called rA. What I am trying to achieve is that all of those instances have a reference to the exact same resource. So to concrete in Swift terms: Class A has a property called foo: private var foo…
the_critic
  • 12,720
  • 19
  • 67
  • 115
2
votes
1 answer

Does D pass value by copy?

if I do: myclass a = new myclass(); myclass b = a; Does b points to or is a copy of a?
The Mask
  • 17,007
  • 37
  • 111
  • 185
2
votes
3 answers

meaning of reference and pointer together?

In my project, there is a definition of a function call like this. int32 Map(void * &pMemoryPointer) In the calling place, the paramenter passed is void*, why cant we just receive it as a pointer itself, instead of this?
Saran-san
  • 361
  • 3
  • 14
1
vote
1 answer

Why am I receiving a heap corruption error in IntegerSet class?

I have an assignment in which I have to create a class called IntegerSet. The point is that it creates sets of integers. If an integer is present in the set, then that number has a 1 in its place in the array set, and a 0 if not. I have been…
1
vote
1 answer

c++ pointers with overloaded functions and user input

I'm getting multiple errors.. I've tried this with different variables and different data types. I clearly don't understand how to use pointers properly. I am not looking for someone to give me the answer, I would like to learn more and figure it…
Tamara
  • 27
  • 1
  • 7
1
vote
2 answers

Passing a pointer as a function argument

I am passing a pointer to a function with intent of modifying the data kept at the original address. #include using namespace std; void square(int **x) { **x = **x + 2; cout<<**x<<" "; } int main() { int y = 5; int *x…
1
vote
2 answers

Deleting a list with pointer to pointer in C

The partial code, in C, is here: typedef struct List { double v; struct List *next; } List; void deleteList (List **p) { *p = (*p)->next; } I am confused about how the deleteList function is working. So the arguement is a pointer to a…
1
vote
2 answers

The address always returned is 0 instead of the actual value

Here is the simple code: int *ad_return() { int a=600; cout << &a << endl; return &a; } int main() { cout << ad_return(); return 0; } The output is unexpected. The first cout prints an address that looks like a address but the…