get pointer value from parameter

Justin Robinson

I am learning how to use pointers in C and I am having trouble with this little program. In main, I want to get the value in the parameter.

int testing(int *number)  {

   int num = 12;
   number = #
   return 0;
}


int main() {

   int num;
   testing(&num);
   printf("The number is: %d", num);

   return 0;
}

Essentially, I want to print the num pointer after it goes through the testing function. Therefore, I want num to be 12. Currently, when I print num, it is a random number. Any ideas? Thanks.

MikeCAT

number = # is changing the local parameter (copy of what is passed). This means nothing because number is not used after that.

Instead of that, you should dereference the passed pointer to write the integer there: *number = num;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JNA : Get value from a pointer to a pointer to a structure

Get value from pointer

Get the value of a Cython pointer

Python YAML parameter reference (get value from other parameter)

Windows shell: get parameter value from file

Get value from js and pass it as parameter

Get Value from parameter function

How to get value of char pointer from Python code wtih ctypes

How to get singly linked list node value from pointer to pointer of that node?

Terraform - Get a value from parameter store and pass to resource

Using pointer in function to get value from the input

Structs and unions: which is better from a performance point of view? Passing the parameter by value or pointer?

How I can get second value from function using *pointer?

How to return value from DLL using parameter of function as a pointer in C++?

get raw value from URL parameter in reactjs

Get value from sql select if parameter may be null

Get type parameter value from URL with livewire

Get previous first value from parameter

Get Boolean Value from VM Parameter in Scala

Get the value from Output parameter C#

get parameter value from form select instead of querystring

Get value of parameter from text file using sed

Get parameter value from method in another class

Get value from AWS Parameter store in Java

get the value of a parameter from a data class in kotlin

const pointer and pointer to const value as parameter

use unsafe pointer to get value from a []string

How to get parameter value from link in flutter?

How to get parameter value from query string?