Link Between Pointer and Variable
When you modify the value through the dereferenced pointer, you are essentially modifying the content of the memory location it points to. This directly affects the original variable.
Remember
Changing the value through
*(p_variable)is equivalent to changing the value ofvariable.
Swipe to start coding
In real-world monitoring systems, sensor readings can sometimes be invalid or out of expected range.
For example, a temperature sensor might give negative values due to errors, or a sensor might report values above the maximum allowed limit.
In this task, you will implement a function that normalizes a sensor reading using a pointer.
The normalization rules are:
-
If the sensor reading is negative, set it to
0. -
If the sensor reading is greater than 100, set it to
100.
- Inside the
normalizeSensorfunction, use the pointer to access the sensor value (*p_sensor). - Apply the normalization rules:
- If the value pointed to by the pointer is less than
0, set it to0. - If the value pointed to by the pointer is greater than
100, set it to100.
- If the value pointed to by the pointer is less than
- Do not modify any variables outside of this function; all changes must be done through the pointer.
Ratkaisu
solution.cpp
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 5.88
Link Between Pointer and Variable
Pyyhkäise näyttääksesi valikon
When you modify the value through the dereferenced pointer, you are essentially modifying the content of the memory location it points to. This directly affects the original variable.
Remember
Changing the value through
*(p_variable)is equivalent to changing the value ofvariable.
Swipe to start coding
In real-world monitoring systems, sensor readings can sometimes be invalid or out of expected range.
For example, a temperature sensor might give negative values due to errors, or a sensor might report values above the maximum allowed limit.
In this task, you will implement a function that normalizes a sensor reading using a pointer.
The normalization rules are:
-
If the sensor reading is negative, set it to
0. -
If the sensor reading is greater than 100, set it to
100.
- Inside the
normalizeSensorfunction, use the pointer to access the sensor value (*p_sensor). - Apply the normalization rules:
- If the value pointed to by the pointer is less than
0, set it to0. - If the value pointed to by the pointer is greater than
100, set it to100.
- If the value pointed to by the pointer is less than
- Do not modify any variables outside of this function; all changes must be done through the pointer.
Ratkaisu
solution.cpp
Kiitos palautteestasi!
single