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()//  ww w  . j a v a  2 s  .  c  o 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