Answer:
The solution for the given question can be outlined as follows:
Program:
#include <stdio.h> // include the header file
int main() // declare the main function
{
int* numItemsPointer; // declare a pointer for integer
int numItems; // declare an integer variable
scanf ("%d", &numItems); // receive user input
if(numItems < 0) // check if the input value is negative
{
numItemsPointer = NULL; // set pointer to null
printf ("Items is negative\n"); // output a message
}
else // if the condition is false
{
numItemsPointer = &numItems; // point to the address of numItems
numItems = numItems * 10; // multiply numItems by 10
printf("Items: %d\n", *numItemsPointer); // output the value
}
return 0;
}
Output:
99
Items: 990
Explanation:
The program defines two integer variables, "numItemsPointer" as a pointer and "numItems" as an integer. The user inputs a value which is checked through an if statement to calculate results, detailed as follows:
- In the if condition, if "numItems" is less than 0, it sets its value to "NULL" and prints an appropriate message.
- If the condition is false, it transfers the address of "numItems" to the pointer and then multiplies "numItems" by 10 before printing the value held by the pointer.