Computer Science, asked by shaizali1349, 10 months ago

1. What is the procedure for storing constant in a variable? Give example.

Answers

Answered by pratikkharate58
4

Answer:

In C,CPP you have to use const keyword to define a constant variable

In python we use #define

In java we use final keyword

Explanation:

For example :  iF WE WANT TO FIND AREA OF CIRCLE

#include<iostream>

using namespace std;

   const pi=3.14;

    int main()

   {

      int r;        //RADIUS OF CIRCLE

       cin>>r;

       int area;  

       area=pi*r*r;

       cout<<area;  //This will print area of circle for given radius r

       return 0;

    }

Points to note :- 1) You cannot re-initialize a constant variable

                           2) Can be of any primary Datatypes

                           3) Can be accessed globally

                           4) Lifetime is throughout the program

                            5) Value cannot be modified

Answered by Anonymous
3

Answer:

const int n=10; //A const is not a variable, it is a constant. You can not alter or assign to the //value, you can only use whatever was defined.

Explanation:

Similar questions