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

How can I assign a variable to the pointer of a control element parameter in Visual Basic?

In Visual Basic, control elements such as textboxes seem to act like objects, and therefore if I assign a variable to such an element, it seems to be assigned by reference. For example: TextBox1.Text = "old text" Dim ctrlEl as Object =…
0
votes
1 answer

How to print result of function in C using pointer (w/o return)

My task is to write a function which calculates sum of elements of array. which I did like so: #include #include int sum (int array[], int len){ int i; int sum=0; for (i=0; i
Leonardo
  • 160
  • 2
  • 3
  • 13
0
votes
2 answers

Why did my array get transposed?

I want declare a 2D array of doubles (double** data). I want to pass this by address to a helper function; so I pass &data and the helper function has argument double*** d. Passed this way, the indexing that I used for the 2D array in the main…
kingledion
  • 2,263
  • 3
  • 25
  • 39
0
votes
3 answers

Why does std::atomic_fetch take a pointer as its input parameter

The set of free functions for std::atomic_fetch_xxx (or, and, add, sub, xor), take as input a std::atomic* named obj: template< class T > T atomic_fetch_sub(std::atomic* obj, typename std::atomic::difference_type arg )…
J Mkdjion
  • 352
  • 1
  • 11
0
votes
1 answer

call by pointers and call by value C

How to write this C program pass by pointers and pass by value? I created this program that generates a 10x10 array from -100 to 100 and the main diagonal is read from bottom to top, but I do not know how to create two other programs that are pass…
0
votes
2 answers

Why pointer argv is not updating?

Can somebody help me understand why the pointer head is not updated after new() call? expected: val:0 # call new(), update l0.val to 0 actual: val:253784 # why update l0.val not update by the…
Tom Ma
  • 1
  • 4
0
votes
0 answers

Setting pointer address from function

I'm new to C and new to asking questions. I've read multiple topic and questions on this . If I missed a similar question I'm sorry . I have an array that I declare in a function. I want to save the adress of the array so later i can find a value…
0
votes
1 answer

pointers and passing variable values from one function to another. how to pass variable values using pointers

I need to have the bowl functions pass b1 and b2 into turntotal to add the two together in a different function. Here is the code, what am I doing wrong? void bowl(){ int b1=rand()%11; int b2=rand()%(11-(b1)); int…
user7176564
  • 1
  • 1
  • 2
0
votes
2 answers

Data Loss When Passing Object

I have an object @interface QuestionViewModel : NSObject @property (nonatomic, assign) NSInteger questionId; @property (nonatomic, strong) NSString *questionText; @property (nonatomic, assign) NSInteger questionNumber; @property (nonatomic, strong)…
0
votes
1 answer

Data from a static vector left unchanged when I leave the method

This is a Bank project I had in mind while learning C++ and I have been adding to it as I learned inheritance and pointers. The user is a bank teller who can create a new customer or process transactions of an existing customer. A Customer has…
0
votes
2 answers

Using scanf() with a pointer to a double pointer

I feel like I've attempted every combination I know of to get this to work and can't figure it out. How can I scanf() into an int** passed as a pointer to a function? I tried searching but couldn't find this, if it's a duplicate please let me know…
Austin
  • 6,921
  • 12
  • 73
  • 138
0
votes
1 answer

Why should I prefer references on smart pointers over smart pointers as parameters in C++

I am currently working on some code (c++11), which makes heavy use of references on pointers, e.g. class SomeClass; class MyClass { public: MyClass( const std::shared_ptr < SomeClass > & class) : m_class(class) {} private: …
John
  • 67
  • 1
  • 7
0
votes
3 answers

why is this pass by pointer is not working as intended?

I am trying to understand why the following code does not work... please help: void incme(double *p) { printf("%x,%x\n",p,*p); *p = *p + 1; printf("%x,%x\n",p,*p); } int main() { int i = 1; incme((double *)&i); …
user1998844
  • 449
  • 8
  • 18
0
votes
2 answers

Could Pass-by-Reference be implemented without pointers?

This might be more a question on computer architecture than on C++ itself, but I was wondering if pass-by-reference could theoretically be implemented without using pointers in a language like C++. Here are three examples of code that have similar…
Navneeth
  • 373
  • 3
  • 15
0
votes
3 answers

End of integer/structure array?

Consider the following functions void alloco(int **ppa) { int i; printf("inside alloco %d\n",ppa); /*this function allocates and fills 20 * sizeof(int) bytes */ *ppa = (int *)malloc(20 * sizeof(int)); /*fill all 20 * sizeof(int)…
pa1
  • 778
  • 3
  • 11
  • 26