0
calc(mesh, prob_data, &cells_fd[crr], species, cr); 

I'm looking at a function call in a code, and I just wanted to verify if I am looking this correct. In the above call, I am interested in the argument cells_fd[crr]. Does the "&" in front of the argument mean that cells_fd[crr] is being passed into the function calc, and whatever calc does, will be stored back inside cells_fd[crr]?

2 Answers 2

1

cells_fd[crr] is equivalent to *(cells_fd + crr), and thus &cells_fd[crr] is equivalent to &*(cells_fd + crr) which is (cells_fd + crr) as the dereference and address operators cancel out.

Thus, your interpretation is correct in that &cells_fd[crr] passes the address of cells_fd[crr], so that calc() may overwrite the contents, but what calc() actually does with the address is not clear from that single line of code without further context.

Sign up to request clarification or add additional context in comments.

Comments

0

"&" it's mean you pass the pointer to call function

i don't know what data type is cells_fd[crr]

#include "stdio.h"
void call( int * i ){
  int iValue = *i; //retrieve value saved in pointer
  int iResult = iValue * 1000; //any calc

  *i = iResult; //save new value in pointer
}

int main(){
  int i = 123;
  printf("initial value: %d\n", i);
  call( &i );
  printf("value after: %d\n", i);
  return 0;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.