C Language / Variables, DataTypes and Constants

Variables
It is a data named used to store a data value and need declare the variables for its types in c language.

Initialization of variables
Giving value to variables is called Initialization of variables.

Example
Declaration Int x ;
Initialization X=9;
Declaration and Initialization Int x =9;

Data Type
It tells the system / Computer to allocate how much space required by the variable name  and what type of variable it is.

C constants
Constant Type Constant SubType Example
Numeric Integer 5,12, 2, -2,4
Real 23.12, 23.12
Character single ‘A’,’w’,’e’,’s’
Backslashcharacter \b, \f, \n, \r e.t.c
String “Wisdom”, “Materials”


Type Size (bytes) Format Specifier
int at least 2, usually 4 %d
char 1 %c
float 4 %f
double 8 %lf
short int 2 usually %hd
unsigned int at least 2, usually 4 %u
long int at least 4, usually 8 %li
long long int at least 8 %lli
unsigned long int at least 4 %lu
unsigned long long int at least 8 %llu
signed char 1 %c
unsigned char 1 %c
long double at least 10, usually 12 or 16 %Lf

Constants in c Language
It is a variable value cannot be changed. during the execution of a problem and is defined with const keyword in the c program.

Example
const double PI = 3.14; ok
const double PI = 3.14; PI = 2.9; Error

There are 2 types of constants in C. Numeric and Character.
Backslashcharacter/Escape Sequence character Meaning
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\” Double quote
\’ Single quote
\\ Backslash
\v Vertical tab
\a Alert or bell
\? Question mark


Home     Back