C - Write program to assign value to int and float via its pointer.

Requirements

Write code that declares an int variable and a float variable.

Use corresponding pointer variables to assign values to those variables.

Display the results by using the int and float variables (not the pointer variables).

Demo

#include <stdio.h>

int main()/*from   www .  j  ava2s  . c  o  m*/
{
    int age;
    float weight;
    int *a;
    float *w;

    a = &age;           // Initialize the pointers
    w = &weight;

    *a = 43;            // Set the values using
    *w = 217.6;         //  the pointers

    printf("You are %d years old\n",age);
    printf("And you weigh %.1f pounds.\n",weight);

    return(0);
}

Result

Related Topic