C - Write program to create function to change float value via pointer

Requirements

Declare a float pointer variable p in the main() function.

Initialize p to the price variable's location, and then pass p to the discount() function.

Demo

#include <stdio.h>

void discount(float *a);

int main()//from  w  ww  .  j  a va2 s  .  co m
{
    float price = 42.99;
    float *p;

    p = &price;
    printf("The item costs $%.2f\n",price);
    discount(p);
    printf("With the discount, that's $%.2f\n",price);
    return(0);
}

void discount(float *a)
{
    *a = *a * 0.90;
}

Result

Related Exercise