SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Introduction to
Farzana Shah
(BS-IT, MBA-HRM)
Lecturer : (Computer Science)
Contents
LEC# 03
Introduction
History
Features
Program compilation process
Program structure
 Examples
 Escape Sequance
 Examples
 Comments
 Examples
 C Language Errors
2
What is c language:-
C is mother language of all programming
language.
It is system programming language.
It is procedure-oriented programming
language.
It is also called mid level programming
language.
A brief history of C
 C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970.
Ken used B to write one of the first implementations of UNIX. B in turn was a
descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most
of its instructions removed.
 So many instructions were removed in going from BCPL to B, that Dennis Ritchie of
Bell Labs put some back in (in 1972), and called the language C.
 The famous book The C Programming Language was written by Kernighan and
Ritchie in 1978, and was the definitive reference book on C for almost a decade.
 The original C was still too limiting, and not standardized, and so in 1983 an ANSI
committee was established to formalise the language definition.
 It has taken until now (ten years later) for the ANSI ( American National Standard
Institute) standard to become well accepted and almost universally supported by
compilers
Language year Developed By
ALGOL 1960 InternationalGroup
BPCL 1967 Martin Richards
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K & R C 1978 Kernighan &Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISOC 1990 ISO Committee
C99 1999 Standardization
Committee
Summary of C language history
Features ofC
The main features of C is; It is Structure oriented
programming languageand it isaverysimpleandeasy
languageztoreadandwrite,
Credit: Tutorial4us.com
Someimportant featuresof C are
1. Structure Oriented
2. PlatformDependent
3. CompilerBased
4.Simpleand easyto learn
5. Hug functionlibrary
6. Usesof pointerconcept
7.Syntaxbased
8, PowerFull
9. Middlelevel programming
10. CaseSensitive
IDE: The Integrated Development Environment
 Turbo c features as integrated Development
environment, or IDE,. It is also referred to as the
programmer’s platform.) in IDE you can able to
write/save/open your programs or code, compile
using short cut keys, and also perform code
debugging very easily.
 Common Short cut Keys Description
 F2 press to Save current work
 F3 press to open an existing file
 ALT-F3 press to close current
 ALT-F9 press to compile only
 ALT-F5 press to view the desired output of the
program.
 CTRL-F9 press to compile+run
 ALT-X or ALT-F-X press to exit from TC IDE
IDE: The Integrated Development Environment
C Programs STRUCTURE (General)
 <Preprocessor Directives (some time necessary)>
 <Macros Definition (optional)>
 <function declaration>
 < Global Variable (on your demand)>
 main () (Necessary)
 { statements }
 < function definition>
 { }
Remember Some common rules for writing C
program
 Use all commands or statements in lower or small case.
 After completion of a statement excluding main() or loops must
insert ; (semicolon) as a statement terminator.
 Don’t use/declare identifier or variable name same as statement
name suppose int
 include; this is a wrong statement because include has a special
meaning in the language.
Learning C:
z
Compiling & Executing C Program:
Compiling & Executing C Programs
 C compiler: This program translates the C language source code
into the machine assembly language.
 Assembler: The assembler accepts the C – compiler output and
creates object code. If the program does not contain any external
function calls, this code is directly executable.
 Linker: If a source file references library functions, which is
defined in other source files, the linker combines these functions
with the main() function to create an executable program file.
C Program: Steps
 Step 1: The program that is to be compiled is first typed into a
file on the computer system. There are various conventions that
are used for naming files, typically be any name provided the last
two characters are “.c” or file with extension .c. So, the file name
prog1.c might be a valid filename for a C program. The program
that is entered into the file
 is known as the source program because it represents the
original form of the program expressed in the C language.
C Program: Steps
 Step 2: After the source program has been entered
into a file, then proceed to have it compiled.
 Typical errors reported during this phase of
compilation might be due to an expression that has
unbalanced parentheses (syntactic error), or due to
the use of a variable that is not “defined” (semantic
error).
C Program: Steps
 Step 3: When all the syntactic and semantic errors
have been removed from the program, the compiler
then proceeds to take each statement of the program
and translate it into a “lower” form that is equivalent
to assembly language program needed to perform
the identical task.
C Program: Steps
 Step 4: After the program has been translated the
next step in the compilation process is to translate
the assembly language statements into actual
machine instructions. The assembler takes each
assembly language statement and converts it into a
binary format known as object code, which is then
written into another file on the system. This file has
the same name as the source file under Unix, with
the last letter an “o” (for object) instead of a “c”.
C Program: Steps
 Step 5: After the program has been translated into
object code, it is ready to be linked. This process is
once again performed automatically whenever the cc
or gcc command is issued under Unix. The purpose
of the linking phase is to get the program into a final
form for execution on the computer.
C Program: Steps
 Step 6: The final linked file, which is in an
executable object code format, is stored in another
file on the system, ready to be run or executed..
Header Files or Preprocessor Directives
 C preprocessor: This program accepts C source files as input and
produces a file that is passed to the compiler.
 The preprocessor is responsible for removing comments and interpreting
special C language pre-processor directives, which can be easily
identified as they begin with the # symbol.
 # include: The preprocessor adds the information about the object code
used in the body of the main function. These files are called headerfiles.
 # define: this directive assigns a symbolic name to a constant.
 Symbolic names are used to make programs more readable and
maintainable.
Header Files or Preprocessor Directives
 Header Files or Preprocessor Directives contains references or links of
 library functions. That is built-in in the C language.
 Suppose if you want to use a function clrscr() ; in the main function so must be
declared on top # include <conio.h> other wise you could have an prototype error.
 Some header files are as follows
 Stdio.h
 Conio.h
 Dos.h
 String.h
 math.h
 And many more header files are available in C…
Main() function: void main(void)
 Every C programs consists of one or more functions. No
matter how many functions there are in a C program , main
is the one to which control is passed from the operating
system when the program is run ; it is the first function
executed.
 The word "void" preceding "main" specifies that the function
main() will not return a value.
 The second "void," in parenthesis , specifies that the
function takes no arguments.
printf() function
 printf() is built-in function we can display with
printf() any message, variable value on
screen/file/printer.
 In printf() we can use many escape
sequences and format specifies.
First Program of C Language:-
#include <stdio.h>
#include <conio.h>
void main(){
printf("Hello CLanguage");
getch();
}
Output of Program is:-
Hello CLanguage
Describe theC Program:-
#include <stdio.h> includes the standard input
output library functions. The printf() function is defined in
stdio.h .
#include <conio.h> includes the console input
output library functions. The getch() function is defined in
conio.h file.
void main() The main() function is the entry point of
every program in c language. The void keyword specifies
that it returns no value.
printf() The printf() function is used to print data on the
console.
getch() The getch() function asks for a single
character. Until you press any key, it blocks the screen.
Escape sequences
 Escape sequences are special notations through which we can display our data Variety of
ways:
 Some escape sequences and their functions are as follows:
Perform line feed (new line ) & Carriage return operation printf("AnB");
 Escape Sequence Description Example
 n
 t
 ’
 “
 r
 b
Prints a tab sequence on screen printf ("Atb");
Prints a single quote character on screen printf ("’a’");
Prints a double quote character on Screen printf (""a"");
Perform carriage return operation printf ("arb")
Remove one character from left printf ("abHi!" );
Escape Sequence
Program of CLanguage:-
#include <stdio.h>
#include <conio.h>
void main(void)
{
clrscr();
printf( " " C Language" n");
getch();
}
Output:
" C Language "
Output of Program is:-
Rules for Comment
 Comments : code which are not executable statement, of
necessary can be placed in between /* and */.
 Comment in the program should be enclosed within /* .. */ .Look example below
the first line is comment.
 For ex. /*This my first program*/
 #include<stdio.h>
 main()
 {
 Statement;
 Statement;
 }
Rules for Comment
 Though comments are not necessary, but it good practice to begin programwith
comment indicating purpose of program so that other person can get idea of
program.
 You can write any number comment at any place in program mentioning the
purpose of the statement.
 Use few Comment instead of too many.
 A comment cannot be nested. For ex., /* The/*first/*program*/*/*/.
 // use for single line comment and /* */ multiple line
 A comment can split over more than one line. Forex.
/*THE
First
Program*/
Escape Sequence, Comments use in CLanguage:-
Output of Program is:-
C Programming Error Types – Runtime,
Compile & Logical Errors
 While writing c programs, errors also known as bugs in the world
of programming may occur unwillingly which may prevent the
program to compile and run correctly as per the expectation of
the programmer.
 Basically there are three types of errors in c programming:
 Runtime Errors
 Compile Errors
 Logical Errors
C Runtime Errors
 C runtime errors are those errors that occur during the
execution of a c program and generally occur due to some
illegal operation performed in the program.
 Examples of some illegal operations that may produce
runtime errors are:
 Dividing a number by zero
 Trying to open a file which is not created
 Lack of free memory space
Compile Errors
 Compile errors are those errors that occur at the time of compilation
of the program. C compile errors may be further classified as:
 Syntax Errors
 When the rules of the c programming language are not followed,
the compiler will show syntax errors.
 For example, consider the statement:
int a,b:
 The above statement will produce syntax error as the statement is
terminated with : rather than ;
Compile Errors
 Semantic Errors
 Semantic errors are reported by the compiler when the
statements written in the c program are not meaningful to the
compiler.
 For example, consider the statement,
b+c=a;
 In the above statement we are trying to assign value of a in the
value obtained by summation of b and c which has no meaning
in c. The correct statement will be
a=b+c;
Logical Errors
 Logical errors are the errors in the output of the
program. The presence of logical errors leads to
undesired or incorrect output and are caused due to
error in the logic applied in the program to produce the
desired output.
 Also, logical errors could not be detected by the
compiler, and thus, programmers has to check the
entire coding of a c program line by line.
Thank you
Question &
Answer

Weitere ähnliche Inhalte

Was ist angesagt?

The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAkshay Ithape
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAlpana Gupta
 
Computer programming chapter ( 3 )
Computer programming chapter ( 3 ) Computer programming chapter ( 3 )
Computer programming chapter ( 3 ) Ibrahim Elewah
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports Sunil Kumar R
 
introduction to C programming (C)
introduction to C programming (C)introduction to C programming (C)
introduction to C programming (C)Abhishek Walia
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming languageKumar Gaurav
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Nuzhat Memon
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming Hemantha Kulathilake
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chaptersIbrahim Elewah
 
C programming basics
C  programming basicsC  programming basics
C programming basicsargusacademy
 

Was ist angesagt? (20)

The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C basics
C   basicsC   basics
C basics
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Computer programming chapter ( 3 )
Computer programming chapter ( 3 ) Computer programming chapter ( 3 )
Computer programming chapter ( 3 )
 
C Language
C LanguageC Language
C Language
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
 
introduction to C programming (C)
introduction to C programming (C)introduction to C programming (C)
introduction to C programming (C)
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
 
C programming basics
C  programming basicsC  programming basics
C programming basics
 

Ähnlich wie Introduction of c language

Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxAbdalla536859
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)TejaswiB4
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRokonuzzaman Rony
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYRajeshkumar Reddy
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)aaravSingh41
 

Ähnlich wie Introduction of c language (20)

C language
C languageC language
C language
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C
CC
C
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptx
 
Programming in c
Programming in cProgramming in c
Programming in c
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
 
C intro
C introC intro
C intro
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
Unit 2 l1
Unit 2 l1Unit 2 l1
Unit 2 l1
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 

Mehr von farishah

INTRODUCTION TO HARDWARE
INTRODUCTION TO HARDWAREINTRODUCTION TO HARDWARE
INTRODUCTION TO HARDWAREfarishah
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computerfarishah
 
Computer applications to business
Computer applications to businessComputer applications to business
Computer applications to businessfarishah
 
Types of software
Types of softwareTypes of software
Types of softwarefarishah
 
Letter writing essentials
Letter writing essentialsLetter writing essentials
Letter writing essentialsfarishah
 

Mehr von farishah (6)

INTRODUCTION TO HARDWARE
INTRODUCTION TO HARDWAREINTRODUCTION TO HARDWARE
INTRODUCTION TO HARDWARE
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Computer applications to business
Computer applications to businessComputer applications to business
Computer applications to business
 
Types of software
Types of softwareTypes of software
Types of software
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Letter writing essentials
Letter writing essentialsLetter writing essentials
Letter writing essentials
 

Kürzlich hochgeladen

Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Kürzlich hochgeladen (20)

Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Introduction of c language

  • 1. Introduction to Farzana Shah (BS-IT, MBA-HRM) Lecturer : (Computer Science)
  • 2. Contents LEC# 03 Introduction History Features Program compilation process Program structure  Examples  Escape Sequance  Examples  Comments  Examples  C Language Errors 2
  • 3. What is c language:- C is mother language of all programming language. It is system programming language. It is procedure-oriented programming language. It is also called mid level programming language.
  • 4. A brief history of C  C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970. Ken used B to write one of the first implementations of UNIX. B in turn was a descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most of its instructions removed.  So many instructions were removed in going from BCPL to B, that Dennis Ritchie of Bell Labs put some back in (in 1972), and called the language C.  The famous book The C Programming Language was written by Kernighan and Ritchie in 1978, and was the definitive reference book on C for almost a decade.  The original C was still too limiting, and not standardized, and so in 1983 an ANSI committee was established to formalise the language definition.  It has taken until now (ten years later) for the ANSI ( American National Standard Institute) standard to become well accepted and almost universally supported by compilers
  • 5. Language year Developed By ALGOL 1960 InternationalGroup BPCL 1967 Martin Richards B 1970 Ken Thompson Traditional C 1972 Dennis Ritchie K & R C 1978 Kernighan &Dennis Ritchie ANSI C 1989 ANSI Committee ANSI/ISOC 1990 ISO Committee C99 1999 Standardization Committee Summary of C language history
  • 6. Features ofC The main features of C is; It is Structure oriented programming languageand it isaverysimpleandeasy languageztoreadandwrite,
  • 8. Someimportant featuresof C are 1. Structure Oriented 2. PlatformDependent 3. CompilerBased 4.Simpleand easyto learn 5. Hug functionlibrary 6. Usesof pointerconcept 7.Syntaxbased 8, PowerFull 9. Middlelevel programming 10. CaseSensitive
  • 9. IDE: The Integrated Development Environment  Turbo c features as integrated Development environment, or IDE,. It is also referred to as the programmer’s platform.) in IDE you can able to write/save/open your programs or code, compile using short cut keys, and also perform code debugging very easily.
  • 10.
  • 11.  Common Short cut Keys Description  F2 press to Save current work  F3 press to open an existing file  ALT-F3 press to close current  ALT-F9 press to compile only  ALT-F5 press to view the desired output of the program.  CTRL-F9 press to compile+run  ALT-X or ALT-F-X press to exit from TC IDE IDE: The Integrated Development Environment
  • 12. C Programs STRUCTURE (General)  <Preprocessor Directives (some time necessary)>  <Macros Definition (optional)>  <function declaration>  < Global Variable (on your demand)>  main () (Necessary)  { statements }  < function definition>  { }
  • 13. Remember Some common rules for writing C program  Use all commands or statements in lower or small case.  After completion of a statement excluding main() or loops must insert ; (semicolon) as a statement terminator.  Don’t use/declare identifier or variable name same as statement name suppose int  include; this is a wrong statement because include has a special meaning in the language.
  • 16. Compiling & Executing C Programs  C compiler: This program translates the C language source code into the machine assembly language.  Assembler: The assembler accepts the C – compiler output and creates object code. If the program does not contain any external function calls, this code is directly executable.  Linker: If a source file references library functions, which is defined in other source files, the linker combines these functions with the main() function to create an executable program file.
  • 17. C Program: Steps  Step 1: The program that is to be compiled is first typed into a file on the computer system. There are various conventions that are used for naming files, typically be any name provided the last two characters are “.c” or file with extension .c. So, the file name prog1.c might be a valid filename for a C program. The program that is entered into the file  is known as the source program because it represents the original form of the program expressed in the C language.
  • 18. C Program: Steps  Step 2: After the source program has been entered into a file, then proceed to have it compiled.  Typical errors reported during this phase of compilation might be due to an expression that has unbalanced parentheses (syntactic error), or due to the use of a variable that is not “defined” (semantic error).
  • 19. C Program: Steps  Step 3: When all the syntactic and semantic errors have been removed from the program, the compiler then proceeds to take each statement of the program and translate it into a “lower” form that is equivalent to assembly language program needed to perform the identical task.
  • 20. C Program: Steps  Step 4: After the program has been translated the next step in the compilation process is to translate the assembly language statements into actual machine instructions. The assembler takes each assembly language statement and converts it into a binary format known as object code, which is then written into another file on the system. This file has the same name as the source file under Unix, with the last letter an “o” (for object) instead of a “c”.
  • 21. C Program: Steps  Step 5: After the program has been translated into object code, it is ready to be linked. This process is once again performed automatically whenever the cc or gcc command is issued under Unix. The purpose of the linking phase is to get the program into a final form for execution on the computer.
  • 22. C Program: Steps  Step 6: The final linked file, which is in an executable object code format, is stored in another file on the system, ready to be run or executed..
  • 23. Header Files or Preprocessor Directives  C preprocessor: This program accepts C source files as input and produces a file that is passed to the compiler.  The preprocessor is responsible for removing comments and interpreting special C language pre-processor directives, which can be easily identified as they begin with the # symbol.  # include: The preprocessor adds the information about the object code used in the body of the main function. These files are called headerfiles.  # define: this directive assigns a symbolic name to a constant.  Symbolic names are used to make programs more readable and maintainable.
  • 24. Header Files or Preprocessor Directives  Header Files or Preprocessor Directives contains references or links of  library functions. That is built-in in the C language.  Suppose if you want to use a function clrscr() ; in the main function so must be declared on top # include <conio.h> other wise you could have an prototype error.  Some header files are as follows  Stdio.h  Conio.h  Dos.h  String.h  math.h  And many more header files are available in C…
  • 25. Main() function: void main(void)  Every C programs consists of one or more functions. No matter how many functions there are in a C program , main is the one to which control is passed from the operating system when the program is run ; it is the first function executed.  The word "void" preceding "main" specifies that the function main() will not return a value.  The second "void," in parenthesis , specifies that the function takes no arguments.
  • 26. printf() function  printf() is built-in function we can display with printf() any message, variable value on screen/file/printer.  In printf() we can use many escape sequences and format specifies.
  • 27. First Program of C Language:- #include <stdio.h> #include <conio.h> void main(){ printf("Hello CLanguage"); getch(); }
  • 28. Output of Program is:- Hello CLanguage
  • 29. Describe theC Program:- #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h . #include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file. void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value. printf() The printf() function is used to print data on the console. getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.
  • 30. Escape sequences  Escape sequences are special notations through which we can display our data Variety of ways:  Some escape sequences and their functions are as follows: Perform line feed (new line ) & Carriage return operation printf("AnB");  Escape Sequence Description Example  n  t  ’  “  r  b Prints a tab sequence on screen printf ("Atb"); Prints a single quote character on screen printf ("’a’"); Prints a double quote character on Screen printf (""a""); Perform carriage return operation printf ("arb") Remove one character from left printf ("abHi!" );
  • 31. Escape Sequence Program of CLanguage:- #include <stdio.h> #include <conio.h> void main(void) { clrscr(); printf( " " C Language" n"); getch(); } Output: " C Language "
  • 33. Rules for Comment  Comments : code which are not executable statement, of necessary can be placed in between /* and */.  Comment in the program should be enclosed within /* .. */ .Look example below the first line is comment.  For ex. /*This my first program*/  #include<stdio.h>  main()  {  Statement;  Statement;  }
  • 34. Rules for Comment  Though comments are not necessary, but it good practice to begin programwith comment indicating purpose of program so that other person can get idea of program.  You can write any number comment at any place in program mentioning the purpose of the statement.  Use few Comment instead of too many.  A comment cannot be nested. For ex., /* The/*first/*program*/*/*/.  // use for single line comment and /* */ multiple line  A comment can split over more than one line. Forex. /*THE First Program*/
  • 35. Escape Sequence, Comments use in CLanguage:-
  • 37. C Programming Error Types – Runtime, Compile & Logical Errors  While writing c programs, errors also known as bugs in the world of programming may occur unwillingly which may prevent the program to compile and run correctly as per the expectation of the programmer.  Basically there are three types of errors in c programming:  Runtime Errors  Compile Errors  Logical Errors
  • 38. C Runtime Errors  C runtime errors are those errors that occur during the execution of a c program and generally occur due to some illegal operation performed in the program.  Examples of some illegal operations that may produce runtime errors are:  Dividing a number by zero  Trying to open a file which is not created  Lack of free memory space
  • 39. Compile Errors  Compile errors are those errors that occur at the time of compilation of the program. C compile errors may be further classified as:  Syntax Errors  When the rules of the c programming language are not followed, the compiler will show syntax errors.  For example, consider the statement: int a,b:  The above statement will produce syntax error as the statement is terminated with : rather than ;
  • 40. Compile Errors  Semantic Errors  Semantic errors are reported by the compiler when the statements written in the c program are not meaningful to the compiler.  For example, consider the statement, b+c=a;  In the above statement we are trying to assign value of a in the value obtained by summation of b and c which has no meaning in c. The correct statement will be a=b+c;
  • 41. Logical Errors  Logical errors are the errors in the output of the program. The presence of logical errors leads to undesired or incorrect output and are caused due to error in the logic applied in the program to produce the desired output.  Also, logical errors could not be detected by the compiler, and thus, programmers has to check the entire coding of a c program line by line.