3.constants, Variables and Data Types
3.constants, Variables and Data Types
Data Types
Introduction
► The set of instructions of the program are formed using certain symbols and words
as per the grammar of the language
► Like any other language, C has its own vocabulary and grammar
The C Character Set
❑ White Spaces
❑ Blank
❑ Horizontal Tab
❑ Carriage Return
❑ New line
❑ Form feed
C Keywords
Keywords in C Programming
auto break case char
const continue default do
double else enum extern
float for goto if
int long register return
short signed sizeof static
struct switch typedef union
unsigned void volatile while
Sample Programs
//Program showing the use of keywords
#include<stdio.h>
int main()
{
int main = 45;
printf("\n main=%d",main);
return 0;
}
Sample Programs
//Program showing the use of keywords
#include<stdio.h>
int main()
{
int main = 45;
int enum = 67;
printf("\n main=%d",main);
printf("\n enum=%d",enum);
return 0;
}
Constants
❑ The largest integer value that can be stored is machine dependent, like 32767 on
16-bit machines, 2,147,483,647 on 32-bit machines
#include<stdio.h>
int main()
{
printf("\n%d",'a');
printf("\n%d",'5');
printf("\n%d",5);
printf("\n%c",'a');
return 0;
}
Constants contd..
❑ String Constants
❑ It is a sequence of characters enclosed in double quotes
❑ The characters may be letters, numbers, special characters
and blank spaces
❑ Examples: “Hello”, “1987”, “X”, “5+3”, “Hello World!”, …
Sample Program
//program showing string constant
#include<stdio.h>
int main()
{
/*printf("\n%d",'a');
printf("\n%d",'5');
printf("\n%d",5);
printf("\n%c",'a');*/
printf("\n%s","X");
printf("\n%s","Hello World!!");
printf("\n%c","A");
return 0;
}
Variables
► A variable is a data name that may ne used to store a data value
► Can have only one value assigned to it at any given time during the execution of
the program
► The value of a variable can be changed during the execution of the program
int main()
{
int x = 20, y=15;
printf("\n x=%d,\t y=%d",x,y);
x=y+3;
printf("\n x=%d,\t y=%d",x,y);
y=x/6;
printf("\n x=%d,\t y=%d",x,y);
return 0;
}
Data Types
► Each variable has a type, indicates what type of values the variable can hold
#include<stdio.h>
int main()
{
const int m = 10;
int p = m+20;
printf("\n m=%d",m);
printf("\n p=%d",p);
return 0;
}
Sample Program