3.3. Basic Elements - Datatype, Variable
3.3. Basic Elements - Datatype, Variable
Module I
Topic – Variables and Data Types
23ADT001 - C PROGRAMMING
Variable
• A variable is nothing but a name given to a storage area that our
programs can manipulate.
Syntax: data type variable name;
Rules for defining variables
• A variable can have alphabets, digits, and underscore.
• A variable name can start with the alphabet, and underscore only. It
can’t start with a digit.
• No whitespace is allowed within the variable name.
• A variable name must not be any reserved word or keyword, e.g. int,
goto, etc.
23ADT001 - C PROGRAMMING
Variable Declaration
To create a variable, you must specify the type and
then its identifier :
Integer
int a;
a=10;
int a=10;
int a,b;
a=10;
b=5;
int a=10,b=5;
23ADT001 - C PROGRAMMING
Variable Declaration
To create a variable, you must specify the type and
then its identifier :
Float
float a;
a=10.5;
float a=10.5;
float a,b;
a=10.5;
b=5.5;
float a=10.5,b=5.5;
23ADT001 - C PROGRAMMING
Variable Declaration
To create a variable, you must specify the type and
then its identifier :
Character
char a;
a=‘x’;
char a=‘x’;
char a,b;
a=‘x’;
b=‘y’;
char a=‘x’,b=‘y’;
23ADT001 - C PROGRAMMING
Variable Declaration
To create a variable, you must specify the type and
then its identifier :
String
char a[5];
a=“hello”;
char a[5]=“hello”;
h e l l o
a[0] a[1] a[2] a[3] a[4]
Representation of string a
23ADT001 - C PROGRAMMING
Variable Initialization
• Variable can be assigned or initialized using an assignment
operator ‘=‘.
• The declaration and initialization can also be done in the same
line.
Syntax:
Variable_name=constant or data_type
Variable_name=constant
23ADT001 - C PROGRAMMING
Entire Data types in c:
Data type Size(bytes) Range Format string
23ADT001 - C PROGRAMMING
References
• Ashok N.Kamthane, Amit.N.Kamthane, “Programming in C”, 3rd
Edition, Pearson Education, 2015
• Ajay Mittal, “Programming in C-A Practical Approach”, 3rd Edition,
Pearson Education, 2010.
• Yashavant P.Kanetkar, “Let Us C”, 16th Edition, BPB Publications,
2018.
• PradipDey, ManasGhosh, “Computer Fundamentals and
Programming in C”, 2nd Edition, Oxford University Press, 2013.
23ADT001 - C PROGRAMMING
23ADT001 - C PROGRAMMING