SlideShare a Scribd company logo
Introduction to C
Introduction to C language – Structure of C program - Character set –
token – identifiers – reserved words – Comments - data types –
constants – printf() function - variables – scanf() function - operators –
expression – declaration statement – assignment statement -
conversion of algorithm in to program – Solving simple problems
involving arithmetic computations and sequential logic to solve.
1
WHY WE LEARN C?
• C language is the most commonly used programming language.
• It is used for writing operating systems.
• UNIX was the first operating system written in C.
• Later Microsoft Windows, Mac OS X, and GNU/Linux were all written in
C.
• Not only is C the language of operating systems, it is the precursor and
inspiration for almost all of the most popular high-level languages available
today.
• In fact, Perl, PHP, Python and Ruby are all written in C.
FEATURES OF C LANGUAGE
• Robust language, which can be used to write any complex
program.
• Well-suited for writing both system software and business
applications.
• Dynamic memory allocation
• C is highly portable. This means that ‘C’ programs written from one
computer can be run on another computer with no modification.
• A ‘C’ program is basically a collection of functions that are supported
by the ‘C’ library
FEATURES OF C LANGUAGE CONT.…
• Program written in C language are efficient & fast.
• ‘C’ is a free form language.
• Case sensitive.
• C has 32 keywords.
• ‘C’ is a structure or procedural programming language that are
use top-down approach.
• Compactness & Reusability
Advantages of C
• General Purpose Language
• Portable Language
• C Provides a collection of Library files
• It support good graphics
• It supports System Programming
• It supports number of operators
• It supports arrays, pointers ,structures and union
• It is used to implementing Data Structure
• It supports structured programming and modularity
Disadvantages in C
•There is no run type checking in c Language
•Non Uniformity in associativity
•It uses same operator for multiple purpose
•It does not support exception handling
•No direct input and output facility
Valid Steps in C Language
• Every step should end with semicolon
• A function name is to be followed by a pair of paranthesis and
arguments are separated by commas
• Single quote(‘) is used for character constant and double quote
(“) is used for string constant
• Compound statements are enclosed within curly braces { }
• Comments are written to improve the readability and
understanding of programs(/*...*/)
Valid Steps in C Language
•All statements should be written in lower case
•Proper header file like <stdio.h> ,<conio.h> are to be used for
systematic programming and linking
•Uppercase characters are used for symbolic constants
•Blank spaces can be inserted between words
•Blank spaces should not be used while declaring a variable
,keyword ,constant and function
•User can write one or more statements in a line separated by
semicolon
•The number of opening and closing braces should be balanced
•Example: a=b+c;m=p*q;
Structure of C program
•C Program is divided into different sections.
•There are six main sections to a basic c program.
The six sections are,
•Documentation
•Link
•Definition
•Global Declarations
•Main Functions
•Subprograms
Structure of C program
Structure of C program
Structure of C program
Structure of C program
Structure of C program
Documentation Section
The documentation section is the part of the program where the
programmer gives the details associated with the program. He/she
usually gives the name of the program, the details of the author and
other details like the time of coding and description. It gives anyone
reading the code the overview of the code.
Example
/**
* File Name: Helloworld.c
* Author: SIT
* description: a program to display hello world
* no input needed
*/
Structure of C program
Link Section
This part of the code is used to declare all the header files that will be
used in the program. This leads to the compiler being told to link the
header files to the system libraries.
Example
#include<stdio.h>
Definition Section
In this section, we define different constants. The keyword define is
used in this part.
#define PI=3.14
Structure of C program
Global Declaration Section
This part of the code is the part where the global variables are declared.
All the global variable used are declared in this part. The user-defined
functions are also declared in this part of the code.
EXAMPLE
float area(float r);
int a=7;
Structure of C program
Main Function Section
Every C-programs needs to have the main function. Each main function
contains 2 parts. A declaration part and an Execution part. The
declaration part is the part where all the variables are declared. The
execution part begins with the curly brackets and ends with the curly
close bracket. Both the declaration and execution part are inside the
curly braces.
EXAMPLE
int main(void)
{
int a=10;
printf(" %d", a);
return 0;
}
Structure of C program
Sub Program Section
• All the user-defined functions are defined in this section of the
program.
• EXAMPLE
• int add(int a, int b)
• {
• return a+b;
• }
Structure of C program
• Sample Program
• The C program here will find the area of a circle using a user-defined function and a global variable pi holding the value of pi
• /** File Name: areaofcircle.c //Documentation section
• * Author: Manthan Naik
• * date: 09/08/2019
• * description: a program to calculate area of circle
• *user enters the radius
• **/
• #include<stdio.h> //link section
• #define pi 3.14; //definition section
• float area(float r); //global declaration
• int main() //main function
• {
• float r;
• printf(" Enter the radius:n");
• scanf("%f",&r);
• printf("the area is: %f",area(r));
• return 0;
• }
• float area(float r)
• {
• return pi * r * r; //sub program
• }
• Output
Character set
• Character is a part of a word ,sentences or paragraph.
• A character set defines the valid characters that can be used in
source programs or interpreted when a program is running.
• The source character set is the set of characters available for the
source text.
C Tokens
Keywords
•Reserved words
•32 keywords
•Fixed meaning which are already defined. It cannot be altered
Identifiers
• C identifiers represent the name in the C program, for example,
variables, functions, arrays, structures, unions, labels, etc.
• An identifier can be composed of letters such as uppercase,
lowercase letters, underscore, digits, but the starting letter should be
either an alphabet or an underscore.
• Example
Identifiers
• Valid Identifiers
name,age,sub,tot_marks,a10
• Invalid Identifiers
2sub,$price,date of birth,auto
Constants
Constants
Comments
Multiline Comments
Variables
• Each variable in C has a specific type, which determines the size
and layout of the variable's memory; the range of values that can be
stored within that memory; and the set of operations that can be
applied to the variable.
• Syntax:
• Data_type variable_name;
• Declaration of Variables : int a=20; int a,b,c;
• float num=10.5;
Rules for declare the Variables

More Related Content

PPTX
Variables in python
PPTX
Operators in python
PPTX
Input output statement in C
PPT
C++ Arrays
PPT
Strings in c
PPSX
5bit field
PPTX
Datatype in c++ unit 3 -topic 2
PDF
Control statements
Variables in python
Operators in python
Input output statement in C
C++ Arrays
Strings in c
5bit field
Datatype in c++ unit 3 -topic 2
Control statements

What's hot (20)

PPTX
Data Types and Variables In C Programming
PPT
File handling in c
PPTX
Python strings presentation
PPTX
Concept of c data types
PPT
Formatted input and output
PPTX
Data Input and Output
PPTX
Function in c
PPT
Functions in c++
PPTX
Stacks in c++
PPT
C++ data types
PPTX
STRINGS IN PYTHON
PDF
Pointers
PPTX
Stack & Queue using Linked List in Data Structure
PPTX
Character set of c
PPTX
Type checking compiler construction Chapter #6
PPTX
Array Of Pointers
PPT
16717 functions in C++
 
PDF
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
PPT
Functions in C++
PPT
Strings Functions in C Programming
Data Types and Variables In C Programming
File handling in c
Python strings presentation
Concept of c data types
Formatted input and output
Data Input and Output
Function in c
Functions in c++
Stacks in c++
C++ data types
STRINGS IN PYTHON
Pointers
Stack & Queue using Linked List in Data Structure
Character set of c
Type checking compiler construction Chapter #6
Array Of Pointers
16717 functions in C++
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
Functions in C++
Strings Functions in C Programming
Ad

Similar to Introduction of c programming unit-ii ppt (20)

PPTX
Copy of UNIT 2 -- Basics Of Programming.pptx
PPTX
Unit-1 (introduction to c language).pptx
PPTX
2.Overview of C language.pptx
PPTX
PROGRAMMING IN C - SARASWATHI RAMALINGAM
PPT
The smartpath information systems c pro
PDF
Introduction to C programming
PPTX
chapter 1.pptx
DOCX
C and DS -unit 1 -Artificial Intelligence and ML.docx
PDF
C program
PDF
C programing for BCA Sem 1. JJ College
DOC
1. introduction to computer
DOCX
Uniti classnotes
PPTX
Basics of C Lecture 2[16097].pptx
PDF
Abc c program
PPTX
C session 1.pptx
PPTX
Computer Programming In C - Variables, Constants & Data Types
PPTX
Unit-1_c.pptx you from the heart of the day revision
PPT
424769021-1-First-C-Program-1-ppt (1).ppt
PDF
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Copy of UNIT 2 -- Basics Of Programming.pptx
Unit-1 (introduction to c language).pptx
2.Overview of C language.pptx
PROGRAMMING IN C - SARASWATHI RAMALINGAM
The smartpath information systems c pro
Introduction to C programming
chapter 1.pptx
C and DS -unit 1 -Artificial Intelligence and ML.docx
C program
C programing for BCA Sem 1. JJ College
1. introduction to computer
Uniti classnotes
Basics of C Lecture 2[16097].pptx
Abc c program
C session 1.pptx
Computer Programming In C - Variables, Constants & Data Types
Unit-1_c.pptx you from the heart of the day revision
424769021-1-First-C-Program-1-ppt (1).ppt
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Onica Farming 24rsclub profitable farm business
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
English Language Teaching from Post-.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Onica Farming 24rsclub profitable farm business
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Open folder Downloads.pdf yes yes ges yes
English Language Teaching from Post-.pdf
Basic Mud Logging Guide for educational purpose
Pharmacology of Heart Failure /Pharmacotherapy of CHF
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction and Scope of Bichemistry.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Week 4 Term 3 Study Techniques revisited.pptx
O7-L3 Supply Chain Operations - ICLT Program
Open Quiz Monsoon Mind Game Prelims.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx

Introduction of c programming unit-ii ppt

  • 1. Introduction to C Introduction to C language – Structure of C program - Character set – token – identifiers – reserved words – Comments - data types – constants – printf() function - variables – scanf() function - operators – expression – declaration statement – assignment statement - conversion of algorithm in to program – Solving simple problems involving arithmetic computations and sequential logic to solve. 1
  • 2. WHY WE LEARN C? • C language is the most commonly used programming language. • It is used for writing operating systems. • UNIX was the first operating system written in C. • Later Microsoft Windows, Mac OS X, and GNU/Linux were all written in C. • Not only is C the language of operating systems, it is the precursor and inspiration for almost all of the most popular high-level languages available today. • In fact, Perl, PHP, Python and Ruby are all written in C.
  • 3. FEATURES OF C LANGUAGE • Robust language, which can be used to write any complex program. • Well-suited for writing both system software and business applications. • Dynamic memory allocation • C is highly portable. This means that ‘C’ programs written from one computer can be run on another computer with no modification. • A ‘C’ program is basically a collection of functions that are supported by the ‘C’ library
  • 4. FEATURES OF C LANGUAGE CONT.… • Program written in C language are efficient & fast. • ‘C’ is a free form language. • Case sensitive. • C has 32 keywords. • ‘C’ is a structure or procedural programming language that are use top-down approach. • Compactness & Reusability
  • 5. Advantages of C • General Purpose Language • Portable Language • C Provides a collection of Library files • It support good graphics • It supports System Programming • It supports number of operators • It supports arrays, pointers ,structures and union • It is used to implementing Data Structure • It supports structured programming and modularity
  • 6. Disadvantages in C •There is no run type checking in c Language •Non Uniformity in associativity •It uses same operator for multiple purpose •It does not support exception handling •No direct input and output facility
  • 7. Valid Steps in C Language • Every step should end with semicolon • A function name is to be followed by a pair of paranthesis and arguments are separated by commas • Single quote(‘) is used for character constant and double quote (“) is used for string constant • Compound statements are enclosed within curly braces { } • Comments are written to improve the readability and understanding of programs(/*...*/)
  • 8. Valid Steps in C Language •All statements should be written in lower case •Proper header file like <stdio.h> ,<conio.h> are to be used for systematic programming and linking •Uppercase characters are used for symbolic constants •Blank spaces can be inserted between words •Blank spaces should not be used while declaring a variable ,keyword ,constant and function •User can write one or more statements in a line separated by semicolon •The number of opening and closing braces should be balanced •Example: a=b+c;m=p*q;
  • 9. Structure of C program •C Program is divided into different sections. •There are six main sections to a basic c program. The six sections are, •Documentation •Link •Definition •Global Declarations •Main Functions •Subprograms
  • 10. Structure of C program
  • 11. Structure of C program
  • 12. Structure of C program
  • 13. Structure of C program
  • 14. Structure of C program Documentation Section The documentation section is the part of the program where the programmer gives the details associated with the program. He/she usually gives the name of the program, the details of the author and other details like the time of coding and description. It gives anyone reading the code the overview of the code. Example /** * File Name: Helloworld.c * Author: SIT * description: a program to display hello world * no input needed */
  • 15. Structure of C program Link Section This part of the code is used to declare all the header files that will be used in the program. This leads to the compiler being told to link the header files to the system libraries. Example #include<stdio.h> Definition Section In this section, we define different constants. The keyword define is used in this part. #define PI=3.14
  • 16. Structure of C program Global Declaration Section This part of the code is the part where the global variables are declared. All the global variable used are declared in this part. The user-defined functions are also declared in this part of the code. EXAMPLE float area(float r); int a=7;
  • 17. Structure of C program Main Function Section Every C-programs needs to have the main function. Each main function contains 2 parts. A declaration part and an Execution part. The declaration part is the part where all the variables are declared. The execution part begins with the curly brackets and ends with the curly close bracket. Both the declaration and execution part are inside the curly braces. EXAMPLE int main(void) { int a=10; printf(" %d", a); return 0; }
  • 18. Structure of C program Sub Program Section • All the user-defined functions are defined in this section of the program. • EXAMPLE • int add(int a, int b) • { • return a+b; • }
  • 19. Structure of C program • Sample Program • The C program here will find the area of a circle using a user-defined function and a global variable pi holding the value of pi • /** File Name: areaofcircle.c //Documentation section • * Author: Manthan Naik • * date: 09/08/2019 • * description: a program to calculate area of circle • *user enters the radius • **/ • #include<stdio.h> //link section • #define pi 3.14; //definition section • float area(float r); //global declaration • int main() //main function • { • float r; • printf(" Enter the radius:n"); • scanf("%f",&r); • printf("the area is: %f",area(r)); • return 0; • } • float area(float r) • { • return pi * r * r; //sub program • } • Output
  • 20. Character set • Character is a part of a word ,sentences or paragraph. • A character set defines the valid characters that can be used in source programs or interpreted when a program is running. • The source character set is the set of characters available for the source text.
  • 22. Keywords •Reserved words •32 keywords •Fixed meaning which are already defined. It cannot be altered
  • 23. Identifiers • C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions, labels, etc. • An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore. • Example
  • 24. Identifiers • Valid Identifiers name,age,sub,tot_marks,a10 • Invalid Identifiers 2sub,$price,date of birth,auto
  • 29. Variables • Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. • Syntax: • Data_type variable_name; • Declaration of Variables : int a=20; int a,b,c; • float num=10.5;
  • 30. Rules for declare the Variables