SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Prepared by:- PRADEEP DWIVEDI (pur. B.TECH-IT) FROM- HINDUSTAN COLLEGE OF SCIENCE &TECHNOLOGY Mob-+919027843806 E-mail-pradeep.it74@gmail.com C-PROGRAMMING SLIDE-2 Monday, August 30, 2010 1 PRADEEP DWIVEDI [pur.B.TECH-IT]
[object Object]
Format of simple c program.
Constant ,variable and data types.
C tokens.
Some program and explanations.TOPIC:- Monday, August 30, 2010 2 PRADEEP DWIVEDI [pur.B.TECH-IT]
SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 3 #include<stdio.h> #include<conio.h>	 void main() { clrscr(); printf(“hello, I am pradeep”); getch(); }
#include directve Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 4 c programs are divided in to modules or functions. some functions are written by users, like us , and many other are stored in the c library. library functions are grouped category-wise and stored in different files known as header files. if we want to access the function stored in the library , it is necessary to tell the compiler about the file to be accessed. this is achieved by using the preprocessor directive #include.
TERMs  RELATED TO PROG Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 5 stdio.h:- standard input output header file scanf()         printf() conio.h:-consol input output header file. clrscr()        getch()                    (clear screen)          (pause screen) ,[object Object],[object Object]
SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 7 this program when executed will produce the following output.  hello, I am pradeep the first inform that the execution of our program begin at this line. the main is a predefine(special) function used by the c system to tell the compiler where the program starts.   every program must have exactly one main function. if we use more than one main function the compiler can not understand which one marks the beginning of the program.
SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 8 the opening brace { in the second line marks the beginning of the function main() and the closing brace } in the last line indicates the end of the function. printf() is a standard predefine c function for printing output. predefined means that it is a function that has already been written and compiled  and linked together with program at the time of linking. the printf function every thing between the starting and the ending quotation marks to be printed out. semicolon(;) sign is called terminator. every statement in c should end with a semicolon.
TERMs  RELATED TO PROG Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 9 clrscr(); is a predefine function that clear the output screen. it comes from conio.h header file. getch(); is also a predefine function which is used to pause the output screen.
FORMAT OF SIMPLE C PROGRAM Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 10 main()                         function name {                              start the program }                                 end the program program statements (body)
CHARACTER SET Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 11 The character in c are grouped into the following categories. Letters Digits Special characters White space
C TOKENS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 12  in a passage of text individual words and punctuation are called tokens. Similarly, in c program the smallest individual units are known as c tokens.
CONSTANTS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 13
VARIABLES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 14 Variables are a place holder that holds the place in computer memory for the value. Because its value may be varied that’s why it is known as variable. int a; (this is called variable declaration). data type        variable. int a=10;(this is called initialization of variable.
DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 15 data type decide that what kind of value should be held by the variable. in c data types are classified into three categories. primary(or fundamental data) types. derived data types. user defined data types.
DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 16
Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 17 DATA TYPES
DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 18 void type:- void has no value. this is usually used to specify the type of function.
KEYWORDS AND IDENTIFIERS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 19 KEYWORDS are the reserve words those are having some predefine meaning and those are only use for their predefine meaning. all keywords in c are in lower case. in c we have 32 keywords. eg, if,  else, for, while, char, int etc. IDENTIFIERS refers to the names of variable, function and arrays.
NAMING RULES AND CONVENTIONS FOR THE VARIABLE NAME(IDENTIFIERS) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 20 a variable name can be anything but it should be short and meaningful. a variable name can not start with a digit. it must be started with an alphabet letter. but a variable name can be followed by n number of digits. it can be started with an underscore sign(_) also. we can not use any special symbol like @,#,*,& in a variable name. we can not use any space in a variable name. if we are having mare than one word in a variable name and space is required that time we can use the underscore(_) sign between them. my_name ,myName. any keywords can not be a variable name.
prog:1 Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 21 /*WRITE A PROGRAM TO ACCEPT A NUMBER FROM THE USER AND PRINT THEM*/ #include<stdio.h> #include<conio.h> void main() { int number; clrscr(); printf("Enter a number"); scanf("%d",&number); printf("the number is: %d",number); getch(); }
TERMs  RELATED TO PROG Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 22 printf() is a predefine function with the help of that we can print the data in any specified format or agates if it is in double quotes. (“           “); scanf() is again a predefine function that can accept data in any specified format.
FORMAT STRING Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 23 format string is used to specify the format of the data . these are following type of:- %d   (decimal) %f  (float) %c  (character) %s  (string) %x (hexadecimal)
ADDRESS OPERATOR(&) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 24 It is used to keep the address of that place where the value is placed.
prog4 Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 25 /*write a program to convert a character to its ascii value*/ #include<stdio.h> #include<conio.h> void main() { char alph; clrscr(); printf("Enter a character"); scanf("%c",&alph); printf("value of character is %c",alph); printf("value of character equivalent is %d",alph); getche(); }
SOME POINTS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 26 note:- each and every character is internally treated as an integer. getch(); is a predefine function that accept a character on the output screen . it just wait for a character. getche(); is having same functionality like getch() function but different is that it displayed the accepted character on the consol screen. getchar(); is also a predefine function that accept a character but that character must be followed by the enter key. note:-drawback of scanf function is that it never accept the space.

Weitere ähnliche Inhalte

Was ist angesagt?

Programming in c function
Programming in c functionProgramming in c function
Programming in c functionParvez Ahmed
 
ภาษาซีพื้นฐาน
ภาษาซีพื้นฐานภาษาซีพื้นฐาน
ภาษาซีพื้นฐานKrunee Thitthamon
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c languageMomenMostafa
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshopneosphere
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringSri Harsha Pamu
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructsGopikaS12
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143alish sha
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]Abhishek Sinha
 
Input and output in c
Input and output in cInput and output in c
Input and output in cRachana Joshi
 

Was ist angesagt? (20)

Programming in c function
Programming in c functionProgramming in c function
Programming in c function
 
ภาษาซีพื้นฐาน
ภาษาซีพื้นฐานภาษาซีพื้นฐาน
ภาษาซีพื้นฐาน
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
 
F# Eye 4 the C# Guy
F# Eye 4 the C# GuyF# Eye 4 the C# Guy
F# Eye 4 the C# Guy
 
Array strings
Array stringsArray strings
Array strings
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
7 functions
7  functions7  functions
7 functions
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143
 
What is c
What is cWhat is c
What is c
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Input and output in c
Input and output in cInput and output in c
Input and output in c
 
C Basics
C BasicsC Basics
C Basics
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 

Ähnlich wie C programming slide c02

MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and AndroidHeiko Behrens
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionEelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxAkhdanMumtaz
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guideTiago Faller
 
Building Hierarchy
Building HierarchyBuilding Hierarchy
Building HierarchyMohamed Samy
 

Ähnlich wie C programming slide c02 (20)

MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and Android
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Function
FunctionFunction
Function
 
Function in cpu 2
Function in cpu 2Function in cpu 2
Function in cpu 2
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax Definition
 
02.adt
02.adt02.adt
02.adt
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Unit 2 ppt
Unit 2 pptUnit 2 ppt
Unit 2 ppt
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Learn C
Learn CLearn C
Learn C
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptx
 
Building Simple C Program
Building Simple  C ProgramBuilding Simple  C Program
Building Simple C Program
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guide
 
Building Hierarchy
Building HierarchyBuilding Hierarchy
Building Hierarchy
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 

C programming slide c02

  • 1. Prepared by:- PRADEEP DWIVEDI (pur. B.TECH-IT) FROM- HINDUSTAN COLLEGE OF SCIENCE &TECHNOLOGY Mob-+919027843806 E-mail-pradeep.it74@gmail.com C-PROGRAMMING SLIDE-2 Monday, August 30, 2010 1 PRADEEP DWIVEDI [pur.B.TECH-IT]
  • 2.
  • 3. Format of simple c program.
  • 6. Some program and explanations.TOPIC:- Monday, August 30, 2010 2 PRADEEP DWIVEDI [pur.B.TECH-IT]
  • 7. SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 3 #include<stdio.h> #include<conio.h> void main() { clrscr(); printf(“hello, I am pradeep”); getch(); }
  • 8. #include directve Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 4 c programs are divided in to modules or functions. some functions are written by users, like us , and many other are stored in the c library. library functions are grouped category-wise and stored in different files known as header files. if we want to access the function stored in the library , it is necessary to tell the compiler about the file to be accessed. this is achieved by using the preprocessor directive #include.
  • 9.
  • 10. SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 7 this program when executed will produce the following output. hello, I am pradeep the first inform that the execution of our program begin at this line. the main is a predefine(special) function used by the c system to tell the compiler where the program starts. every program must have exactly one main function. if we use more than one main function the compiler can not understand which one marks the beginning of the program.
  • 11. SAMPLE PROGRAM(SEE-SAMPLE.C) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 8 the opening brace { in the second line marks the beginning of the function main() and the closing brace } in the last line indicates the end of the function. printf() is a standard predefine c function for printing output. predefined means that it is a function that has already been written and compiled and linked together with program at the time of linking. the printf function every thing between the starting and the ending quotation marks to be printed out. semicolon(;) sign is called terminator. every statement in c should end with a semicolon.
  • 12. TERMs RELATED TO PROG Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 9 clrscr(); is a predefine function that clear the output screen. it comes from conio.h header file. getch(); is also a predefine function which is used to pause the output screen.
  • 13. FORMAT OF SIMPLE C PROGRAM Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 10 main() function name { start the program } end the program program statements (body)
  • 14. CHARACTER SET Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 11 The character in c are grouped into the following categories. Letters Digits Special characters White space
  • 15. C TOKENS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 12 in a passage of text individual words and punctuation are called tokens. Similarly, in c program the smallest individual units are known as c tokens.
  • 16. CONSTANTS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 13
  • 17. VARIABLES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 14 Variables are a place holder that holds the place in computer memory for the value. Because its value may be varied that’s why it is known as variable. int a; (this is called variable declaration). data type variable. int a=10;(this is called initialization of variable.
  • 18. DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 15 data type decide that what kind of value should be held by the variable. in c data types are classified into three categories. primary(or fundamental data) types. derived data types. user defined data types.
  • 19. DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 16
  • 20. Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 17 DATA TYPES
  • 21. DATA TYPES Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 18 void type:- void has no value. this is usually used to specify the type of function.
  • 22. KEYWORDS AND IDENTIFIERS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 19 KEYWORDS are the reserve words those are having some predefine meaning and those are only use for their predefine meaning. all keywords in c are in lower case. in c we have 32 keywords. eg, if, else, for, while, char, int etc. IDENTIFIERS refers to the names of variable, function and arrays.
  • 23. NAMING RULES AND CONVENTIONS FOR THE VARIABLE NAME(IDENTIFIERS) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 20 a variable name can be anything but it should be short and meaningful. a variable name can not start with a digit. it must be started with an alphabet letter. but a variable name can be followed by n number of digits. it can be started with an underscore sign(_) also. we can not use any special symbol like @,#,*,& in a variable name. we can not use any space in a variable name. if we are having mare than one word in a variable name and space is required that time we can use the underscore(_) sign between them. my_name ,myName. any keywords can not be a variable name.
  • 24. prog:1 Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 21 /*WRITE A PROGRAM TO ACCEPT A NUMBER FROM THE USER AND PRINT THEM*/ #include<stdio.h> #include<conio.h> void main() { int number; clrscr(); printf("Enter a number"); scanf("%d",&number); printf("the number is: %d",number); getch(); }
  • 25. TERMs RELATED TO PROG Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 22 printf() is a predefine function with the help of that we can print the data in any specified format or agates if it is in double quotes. (“ “); scanf() is again a predefine function that can accept data in any specified format.
  • 26. FORMAT STRING Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 23 format string is used to specify the format of the data . these are following type of:- %d (decimal) %f (float) %c (character) %s (string) %x (hexadecimal)
  • 27. ADDRESS OPERATOR(&) Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 24 It is used to keep the address of that place where the value is placed.
  • 28. prog4 Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 25 /*write a program to convert a character to its ascii value*/ #include<stdio.h> #include<conio.h> void main() { char alph; clrscr(); printf("Enter a character"); scanf("%c",&alph); printf("value of character is %c",alph); printf("value of character equivalent is %d",alph); getche(); }
  • 29. SOME POINTS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 26 note:- each and every character is internally treated as an integer. getch(); is a predefine function that accept a character on the output screen . it just wait for a character. getche(); is having same functionality like getch() function but different is that it displayed the accepted character on the consol screen. getchar(); is also a predefine function that accept a character but that character must be followed by the enter key. note:-drawback of scanf function is that it never accept the space.
  • 30. COMMENTS Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 27 commets are used to give the better readability of a program. at the time of program execution comments are ignored by the compiler. these are two types of: //single line comments /* multiple line comments */ note:-we can not use nested comments.
  • 31. RETURN TYPE Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 28 It decide what kind of value should be returned by the function. if we don’t use any return type before the function that time by default there is int. return is a keyword with the help of that we can return a value and a value is always return where the function is being called.
  • 32. Monday, August 30, 2010 PRADEEP DWIVEDI [pur.B.TECH-IT] 29 THANKS