June 24, 2021

TriStudy

TriStudy Provide Free Online Tutorials about Programming languages,Digital Marketing, web designing, online earning, web hosting, WordPress etc

C language Variables, Constants and Literals.

c constant

variables.

constant and variables.

In programming, a variable is a holder (stockpiling zone) to hold information.To demonstrate the capacity region, every factor ought to be given an interesting name (identifier). Variable names are only the emblematic portrayal of a memory area. For instance:

int playerScore = 95;

Here, playerScore is a variable of int type. Here, the variable is allocated a number esteem 95.

The estimation of a variable can be changed, consequently the name variable.

scorch ch = ‘a’;

/some code

ch = ‘l’;

Rules for naming a variable

A variable name can have just letters (both capitalized and lowercase letters), digits and underscore.

The principal letter of a variable ought to be either a letter or an underscore.

There is no standard on to what extent a variable name (identifier) can be. In any case, you may run into issues in certain compilers if the variable name is longer than 31 characters.

Note: You ought to consistently attempt to give significant names to factors. For instance: firstName is a superior variable name than fn.

C is a specifically language. This implies the variable sort can’t be changed once it is announced. For instance:

int number = 5;/whole number variable

number = 5.5;/blunder

two fold number;/blunder

Here, the sort of number variable is int. You can’t dole out a gliding point (decimal) esteem 5.5 to this variable. Additionally, you can’t rethink the information kind of the variable to twofold. Incidentally, to store the decimal qualities in C, you have to proclaim its sort to either twofold or glide.

Literals.

A strict is a worth (or an identifier) whose worth can’t be changed in a program. For instance: 1, 2.5, ‘c’ and so forth.

Here, 1,2.5 and ‘c’ are literals. Why? You can’t appoint various qualities to these terms.

Constants.

On the off chance that you need to characterize a variable whose worth can’t be transformed, you can utilize the const catchphrase. This will make a consistent. For instance,

const twofold PI = 3.14;

Notice, we have included catchphrase const.

Here, PI is a representative consistent; its worth can’t be changed.

const twofold PI = 3.14;

PI = 2.9;/Error

visit www.tristudy.com for more.