Differentiate between constant and literals. Why do we need to define the type of data?

This answer is restricted. Please login to view the answer of this question.

Login Now

literal is a value that is expressed as itself. For example, the number 25 or the string “Hello World” are both literal.

constant is a data type that substitutes a literal. Constants are useful in situations where

  • a specific, unchanging value is to be used at various times during the software program
  • you want to more easily understand the software code

A variable in a program can change its value during the course of execution of the program. A constant retains the same value throughout the program.

For example, if you have a constant named PI that you’ll be using at various places in your program to find the area, circumference, etc of a circle, this is a constant as you’ll be reusing its value. But when you’ll be declaring it as:

const float PI = 3.141;

The 3.141 is a literal that you’re using. It doesn’t have any memory address of its own and just sits in the source code whereas PI is a constant of decimal type. It has a memory address also.

Requirement of Data type in c:

Data types used in C language refer to an extensive system that we use to declare various types of functions or variables in a program. Here, on the basis of the type of variable present in a program, we determine the space that it occupies in storage, along with the way in which the stored bit pattern will be interpreted.

A data type specifies the type of data that a variable can store such as integer, floating, character, etc.

Whenever we utilize a data type in a C program, we define the variables or functions used in it. We do so because we must specify the type of data that is in use so that the compiler knows exactly what type of data it must expect from the given program.

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .