VARIABLES AND CONSTANTS IN C
A variable is a name given to a memory location that stores data. The value of a variable can change during program execution. A constant is a value that cannot be changed during program execution.
In the C programming language, a constant is an identifier that contains a specific value. The value cannot be altered during normal C program execution, as the value is constant.
Example
const float PI = 3.1415927; // (Pi is a constant)
for(int i=0;i<10,i++) // i is a variable
Floating-point constants
Floating point constants in C programming are a type of numeric constants that can either take decimal points or exponent form.
Example:
-2.0
0.0000234
-0.22E-5
Integer constants
Integer constants in the C language are a type of numeric constant (constants associated with numbers) that do not have any fractional part or exponential part.
Three types of integer constants are available in the C programming language:
Decimal constant (base 10)
E.g. Decimal numbers: 0 1 2 3 4 5 6 7 8 9
Octal constant (base 8)
E.g. Octal numbers: 0 1 2 3 4 5 6 7
Hexadecimal constant (base 16)
E.g., Hexadecimal numbers: 0 1 2 3 4 5 6 7 8 9 A B C D E F.
Character constants
Character constants in the C language are a type of constant that uses single quotations around characters. For example: ‘l’, ‘o’, ‘v’, ‘e’, etc.
Variables:
An identifier that holds the value that can be altered during normal program execution is called a variable. Variables can be visualized as a memory location in the computer’s memory to store data. In other words, Variable names are just the symbolic representation of a memory location.
In C programming following basic variable types are available:
char: This is an integer type. Consume 1 byte of memory location
int: Contains decimal point-free integer value. Consume 2 bytes of memory
float: Single precision floating point value. Consume 4 bytes of memory
: Double-precision floating point value. Consume 8 bytes of memory
void: Represents the absence of type.
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int a=2;
float b=6.78;
char c=’x’;
double d=456.678;
clrscr();
printf(“integer=%d”,a);
printf(“\nfloat=%lf”,b);
printf(“\nchar=%c”,c);
printf(“\ndouble=%lf”,d);
getch();
}

Example
#include<stdio.h>
main()
{
int i;
float f;
char c;
clrscr();
printf(“size of i= %d”,sizeof (i));
printf(“\nsize of f= %d”, sizeof (f));
printf(“\nsize of c= %d”,sizeof (c));
getch();
}

The C programming language also gives support for two important kinds of variables that could be used for the dynamic allocation of memory.
Static variable:
static int shared = 3; //shared is of static type variable
A static variable is defined outside all blocks and is static. Always declared outside of the main block.
global variable:
A global variable in the C language is a type of variable that has global scope. In other words, a global variable is accessible throughout the program, unless the programmer hides it.
#include <stdio.h>
static int shared = 3; //note declaration of variable just after the library
main()
{
}
Example
#include<stdio.h>
#include<string.h>
void main()
{
int i;
static char name[7]={‘X’,’c’,’n’,’o’,’t’,’e’,’s’};
clrscr();
printf(“\n elements of the array\n”);
for(i=0;i<=6;i++)
printf(“name[%d]=%c\n”,i,name[i]);
getch();
}
