![]() |
| C Variables, Constants, Literals |
Right now, we will find out about factors and rules for naming a variable. You will likewise find out about various literals in C programming and how to make constants.
Variables
A variable is a name that refers to a value that is, which is used to store a value.
To demonstrate the capacity zone, every factor ought to be given a one of a kind name (identifier). Variable names are only the emblematic portrayal of a memory area. For example:
| int score=25; |
|---|
Here, the score is a variable of int type. Here, the variable is assigned an integer value 25.
The estimation of a variable can be changed, subsequently the name variable.
char ch = 'a';
// code here
ch = 'l';
|
|---|
Restriction while giving the variable name
1. Maximum 31 characters are allowed for a name, but it is better to use a maximum of 8 characters.
2. A name can't be started with a digit, but we can use digit after an alphabet.
example: a1, a9
3. No special characters are allowed for a name except underscore(_)
example: ab+❌
a_b✔️
_ab✔️
4. No keywords are allowed for a name.
C is specifically language. This implies the variable kind can't be changed once it is proclaimed. For example:
int number = 10; // integer variable
number = 10.5; // error
double number; // error
|
|---|
Here, the sort of number variable is int. you can't assign a floating-point (decimal) value 5.5 to the present variable. Also, you can't redefine the info sort of the variable to double. By the way, to store the decimal values in C, you would like to declare its type to either double or float.
Visit this page to find out more about different types of data a variable can store.
Literals
Literals are data used for representing fixed values. They can be used directly in the code. For example: 1, 2.5, 'c' etc.Here, 1, 2.5 and 'c' are literals. Why? You cannot assign different values to these terms.
1. Integers
An integer could also be a numeric literal(associated with numbers) with none fractional or exponential part. There are three sorts of integer literals in C programming:- decimal (base 10)
- octal (base 8)
- hexadecimal (base 16)
Decimal: 0, -9, 22 etc
Octal: 021, 077, 033 etc
Hexadecimal: 0x7f, 0x2a, 0x521 etc
|
|---|
2. Floating-point Literals
| Examples: 10.0, 5.1 |
|---|
3. Single character
A single character enclosed within a single quotation(' ') is called a single character constant.
| Examples: 'a', 'A', '5', '?' |
|---|
4. String Literals
| Example: "A", "Programbuzz" |
|---|
Constant
constant is a value that cannot be changed.
| const double IP = 2.14; |
|---|
Notice, that here keyword added const.
Here, IP is constant its value cannot be changed.
const double IP = 2.14;
IP = 3.9; //Error
|
|---|

1 Comments
The determination of what task to do could be daunting when there’s nothing or everything taking precedence. Spin a 우리카지노 wheel of your to do list and knock off every task in a random order. Know your Martingale out of your Fibonacci with this in-depth information to roulette betting methods and means to|tips on how to} use them.
ReplyDelete