Why pointers pass by pointer example

Calling a function that has pass by pointer parameters.

Write a function call with arguments tensPlace, onesPlace, and userInt. Be sure to pass the first two arguments as pointers. Sample output for the given program:

tensPlace = 4, onesPlace = 1
#include <stdio.h>

void SplitIntoTensOnes(int* tensDigit, int* onesDigit, int DecVal){
 *tensDigit = (DecVal / 10) % 10;
 *onesDigit = DecVal % 10;
 return;
}

int main(void) {
 int tensPlace = 0;
 int onesPlace = 0;
 int userInt = 0;

userInt = 41;

SplitIntoTensOnes(&tensPlace, &onesPlace, userInt);

printf("tensPlace = %d, onesPlace = %d\n", tensPlace, onesPlace);

return 0;
}

 

 Pass by pointer: Adjusting start/end times.

 

Define a function UpdateTimeWindow() with parameters timeStart, timeEnd, and offsetAmount. Each parameter is of type int. The function adds offsetAmount to each of the first two parameters. Make the first two parameters pass by pointer. Sample output for the given program:

timeStart = 3, timeEnd = 7
timeStart = 5, timeEnd = 9
#include <stdio.h>

// Define void UpdateTimeWindow(...)

void UpdateTimeWindow(int* timeStart, int* timeEnd, int offsetAmount) {
 *timeStart = *timeStart + offsetAmount;
 *timeEnd = *timeEnd + offsetAmount;
 }

int main(void) {
 int timeStart = 0;
 int timeEnd = 0;
 int offsetAmount = 0;

timeStart = 3;
 timeEnd = 7;
 offsetAmount = 2;
 printf("timeStart = %d, timeEnd = %d\n", timeStart, timeEnd);

UpdateTimeWindow(&timeStart, &timeEnd, offsetAmount);
 printf("timeStart = %d, timeEnd = %d\n", timeStart, timeEnd);

return 0;
}