data structure and c
DESCRIPTION
Data Structure and c. K.S.Prabhu Lecturer All Deaf Educational Technology. C Tokens. C Tokens. Keywords. It has 32 keywords. #include #include void main() { char yn; clrscr(); do {. puts("enter y/n(yes/no)"); yn=getchar(); fflush(stdin); if(yn!='y'&&yn!='n') - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/1.jpg)
Data Structure and c
K.S.PrabhuLecturer
All Deaf Educational Technology
![Page 2: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/2.jpg)
C Tokens
![Page 3: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/3.jpg)
C Tokens
![Page 4: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/4.jpg)
![Page 5: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/5.jpg)
![Page 6: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/6.jpg)
Keywords
• It has 32 keywords. 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
![Page 7: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/7.jpg)
#include<stdio.h>#include<conio.h>void main(){char yn;clrscr();do{
puts("enter y/n(yes/no)");yn=getchar();fflush(stdin);if(yn!='y'&&yn!='n')puts("invalid input");}while(yn!='y'&&yn!='n'); getch();
![Page 8: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/8.jpg)
Constants A constant is an entity that doesn't change
during the execution of a program.
Followings are the different types of constants.
1)Real constant2)Integer Constant 3)Character Constant 4)String Constant
![Page 9: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/9.jpg)
1. Real Constant :
• It must have at least one digit.• It must have a decimal point which may be
positive or negative.• Use of blank space and comma is not allowed
between real constants.• Example:•
+194.143, -416.41
![Page 10: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/10.jpg)
Real Constant
• It must have at least one digit.
• It must have a decimal point which may be positive or
negative.
• Use of blank space and comma is not allowed between
real constants.
• Example:
+194.143, -416.41
![Page 11: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/11.jpg)
Integer Constant
• It must have at least one digit.
• It should not contain a decimal place.
• It can be positive or negative.
• Use of blank space and comma is not allowed between
real constants.
• Example:
•
1990, 194, -394
![Page 12: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/12.jpg)
Character Constant
• It is a single alphabet or a digit or a special
symbol enclosed in a single quote.
• Maximum length of a character constant is 1.
• Example:
'T', '9', '$'
![Page 13: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/13.jpg)
String Constant
• It is collection of characters enclosed in double quotes.
• It may contain letters, digits, special characters and
blank space.
• Example:
“I love Deaf“
“ All Deaf Educational Technology”
![Page 14: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/14.jpg)
Identifier
• An identifier is used for any variable, function, data definition, etc.
• In the C programming language, an identifier is a combination of alphanumeric characters.
• An underline and the remaining being any letter of the alphabet, any numeric digit, or the underline.
![Page 15: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/15.jpg)
![Page 16: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/16.jpg)
String
• Strings in C are represented by arrays of
characters.
• The end of the string is marked with a special
character, the null character, which is simply the
character with the value 0.
• The null character has no relation except in name
to the null pointer.
char string[15] = "Hello world!";
![Page 17: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/17.jpg)
Sample code Program
#include<stdio.h>#include<conio.h>void main(){char in_str[21];clrscr();
puts("Enter a string to a maximum of 20 characters");getch();} outputEnter a string to a maximum of 20 characters
Youth •
![Page 18: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/18.jpg)
Variables
• It is date name used date value called by valuables.
• It is a data name which is used to store data and may change during program execution.
• It is opposite to constant.
![Page 19: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/19.jpg)
• Variable name is a name given to memory cells location of a computer where data is stored.
Syntax:
{data types}{Variables name} =[value]
![Page 20: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/20.jpg)
Sample code Program
Example:Int count index;Float area price;Chal class types;
Example of main program:-
Main{ Int a,b,c,=10; Char x; Float num;
![Page 21: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/21.jpg)
Types of variables
![Page 22: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/22.jpg)
Local variables
•These variables only exist inside the specific function that creates them.
•They are unknown to other functions and to the main program.
•As such, they are normally implemented using a stack.
![Page 23: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/23.jpg)
• Example:• {• Int a, b, c, =10; local variable• Char x;• Float num;• }
![Page 24: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/24.jpg)
Global variables
• These variables can be accessed by any function comprising the program.
• They are implemented by associating memory locations with variable names.
![Page 25: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/25.jpg)
• Example:• {Int a, b, c, =[10,20,30] ; Global variable• Chal x;• Float• } (or)• {Int a = [10]• Int b = [20]• Int c = [30]• Chal [15]• Float• }
![Page 26: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/26.jpg)
Example of Global Variable
Example:{
Int a, b, c, =[10,20,30] ; Char x;Float num;}
{ Int a = [10]; Int b = [20]; Int c = [30]; Char[15]; Float num;}
![Page 27: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/27.jpg)
TYPEDEF STATEMENT
• typedef is a keyword in the C and C++ programming languages.
• The purpose of typedef is to assign alternative
names to existing types.
• types declared with typedef end with ( '_t' )• (e.g., size_t, time_t)Syntax;-• Typedef exp1, exp2,….., exp n
![Page 28: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/28.jpg)
• All data types in between typedef and identifier can now be referred to by the identifier alone The statement.
typedef struct tnode *Treeptr; typedef struct tnode { int count; struct tnode *left; struct tnode *right; } Treenode;
![Page 29: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/29.jpg)
Example of Typedeaf
![Page 30: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/30.jpg)
Enumerated DataTypes
•The data type enum allows used identifier as value
•Syntax:• Enum identifier {Element} Element 1, Element 2…..to Element n;
![Page 31: Data Structure and c](https://reader035.vdocuments.us/reader035/viewer/2022062322/568144ea550346895db1bb78/html5/thumbnails/31.jpg)
Example of main program
• Enum days {sun, mon, tue, wed, thu, fir, sat}
• Enum color{red, blue, orange, pink, green,}
• Enum holiday{Sunday, Saturday}
• Enum rainbow {red, blue, orange, yellow,
green,}