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

Changing variable when passing by value

I have a main function that declares a double. It then passes it to void Display, which displays the double. The main then passes the double (by value) to a function void Pointers which calls the display function and then changes the value of the…
David
  • 43
  • 7
0
votes
2 answers

how do i avoid using pointer variables and pointer-based pass-by-reference in this program?

how do i avoid using pointer variables and pointer-based pass-by-reference in this program? as my instructor said there is no need to use pointers. This is a the tortoise and the hare simulator , you will use number generation to develop a…
0
votes
3 answers

Pointer size and Pass-by-Reference vs. Pass-by-Pointer

I have two questions: Am I right that on 4-bit systems, a pointer is 4 bytes? Are "pass by reference" and "pass by pointer the same thing, just different wording?
Mark
  • 6,052
  • 8
  • 61
  • 129
-1
votes
2 answers

Can I take a reference of a pointer in C++?

I am passing in a reference to a pointer variable into a function. The function will do something and point the pointer variable to some object. Code: int Foo(Obj* &ptr) { // do something... ptr = some_address; return return_value; } int…
Power_tile
  • 578
  • 1
  • 6
  • 18
-1
votes
3 answers

Why am I not getting the desired output for this program using pointers in functions in c?

Header file: circlehead.h #include void circle_Data(float *r); #define PI 3.14f C FILE1: circle.c #include "circlehead.h" void circle_Data(float *r) { float ar=0,peri=0; ar= PI * (*r) * (*r); peri=2 * PI * (*r); } MAIN…
Sneha
  • 29
  • 3
-1
votes
4 answers

Expression "passing by reference" for structs in C

I have recently had a class about structures in C and the lecturer used the expression "pass by reference" to describe the action of passing a pointer towards a structure to a function. I have always read that C does not have "pass by reference"…
-1
votes
2 answers

How to pass a local array to another function call?

I am working on a project which requires certain actions be in their own functions. Right now, I must take the random values generated, and output them FROM an array. I have the values stored in numarray , but I don't know how I can call that array…
-1
votes
1 answer

Whats the difference in using passByRefrence vs passByAddress in this example. C++

As you can see in the example I'm about to provide below I'm using both Pass By Reference and Pass By Address... #include #include void passByAddress(int *a); void passByReference(int &a); int main() { int betty = 21; …
amanuel2
  • 4,508
  • 4
  • 36
  • 67
-2
votes
1 answer

C++ pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

I keep getting this error. I know what function causes it, but don't know how to fix it. Looking up online from this post saying: You need to pass a pointer to a dynamically allocated object, or make your own insde your chainLink class. However,…
user8812816
-3
votes
4 answers

C, pass by value, in Linux

I have a function as follows: void foo (int *check){ *check= 9; printf("*check: %d\n",*check); //when I print "*check" here, the value changes as 9. } This is the main function. void main () { int check=5; foo(&check); printf("check:…
helloword
  • 5
  • 2
-5
votes
4 answers

Pass By Value/Pointer/Reference Clarification

I need a once-and-for-all clarification on passing by value/pointer/reference. If I have a variable such as int SomeInt = 10; And I want to pass it to a function like void DoSomething(int Integer) { Integer = 1; } In my current scenario when…
1 2 3 4 5 6
7