0% found this document useful (0 votes)
9 views12 pages

3.3. Basic Elements - Datatype, Variable

Basic elements

Uploaded by

karthicksrujan16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

3.3. Basic Elements - Datatype, Variable

Basic elements

Uploaded by

karthicksrujan16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

23ADT001 - C Programming

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

Char 1 128 to 127 %c

Unsigned char 1 0 to 255 %c

Short or int 2 -32,768 to 32,767 %i or %d

Unsigned int 2 0 to 65535 %u

Long 4 -2147483648 to 2147483647 %ld

Unsigned long 4 0 to 4294967295 %lu

Float 4 3.4 e-38 to 3.4 e+38 %f or %g

Double 8 1.7 e-308 to 1.7 e+308 %lf

Long Double 10 3.4 e-4932 to 1.1 e+4932 %lf


23ADT001 - C PROGRAMMING
Basic C programs #include<stdio.h>//program to display given data
#include<conio.h>
void main()
{
int a=10; OUTPUT
Integer value : 10
float b=10.88; Float value : 10.88
char c=‘$’; Character :$
String : hello
char d[5]=“hello”;
clrscr();
printf(“Integer value : %d\n”,a);
printf(“Float value : %f\n”,b);
printf(“Character : %c\n”,c);
printf(“String : %s”,d);
getch();
}
23ADT001 - C PROGRAMMING
SUMMARY
• Basic elements of C program
• Data types
• Variables

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

You might also like