Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Link Between Pointer and Variable | Pointers Fundamentals
C++ Pointers and References

bookLink 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 of variable.

Завдання

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.

  1. Inside the normalizeSensor function, use the pointer to access the sensor value (*p_sensor).
  2. Apply the normalization rules:
    • If the value pointed to by the pointer is less than 0, set it to 0.
    • If the value pointed to by the pointer is greater than 100, set it to 100.
  3. Do not modify any variables outside of this function; all changes must be done through the pointer.

Рішення

solution.cpp

solution.cpp

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you give an example of how to use a dereferenced pointer in code?

Why does changing the value through a pointer affect the original variable?

Can you explain what happens if I have multiple pointers to the same variable?

close

Awesome!

Completion rate improved to 5.88

bookLink 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 of variable.

Завдання

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.

  1. Inside the normalizeSensor function, use the pointer to access the sensor value (*p_sensor).
  2. Apply the normalization rules:
    • If the value pointed to by the pointer is less than 0, set it to 0.
    • If the value pointed to by the pointer is greater than 100, set it to 100.
  3. Do not modify any variables outside of this function; all changes must be done through the pointer.

Рішення

solution.cpp

solution.cpp

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

some-alt