#include "stdio.h"
void Square(int num, int *myPointer);
int main(int argc, const char *argv[]) {
int originalNum = 5;
Square(originalNum, &originalNum);
printf("%i\n", originalNum);
return 0;
}
void Square(int num, int *myPointer) {
*myPointer = num*num;
}
I don’t understand how we can pass in &originalNum for a pointer parameter when originalNum is an int. Thanks!
originalNumis an int.&originalNumis a pointer tooriginalNumand thus pointer to an int orint *.In simpler words,
&originalNumis the address where theoriginalNumvariable is allocated in the memory. So, when you pass&originalNumyou don’t pass5(the value oforiginalNum). Instead, you pass the address where this5is stored.