SlideShare a Scribd company logo
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.
Introduction of c language
 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

More Related Content

What's hot (20)

PDF
The C++ Programming Language
Prof Ansari
 
PPT
C PROGRAMMING
Stalongiles Philip
 
PPTX
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
PDF
Introduction to c programming
Akshay Ithape
 
PPTX
C basics
thirumalaikumar3
 
PPTX
Introduction to c programming
Alpana Gupta
 
PDF
Learning the C Language
nTier Custom Solutions
 
PDF
Computer programming chapter ( 3 )
Ibrahim Elewah
 
PPT
C Language
Aakash Singh
 
PPTX
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
PDF
Turbo C Compiler Reports
Sunil Kumar R
 
PPT
introduction to C programming (C)
Abhishek Walia
 
PPT
Brief introduction to the c programming language
Kumar Gaurav
 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
 
PPT
Programming in c
indra Kishor
 
PPSX
C basics 4 std11(GujBoard)
indrasir
 
PPTX
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
PPTX
COM1407: Introduction to C Programming
Hemantha Kulathilake
 
PDF
Computer programming all chapters
Ibrahim Elewah
 
PPSX
C programming basics
argusacademy
 
The C++ Programming Language
Prof Ansari
 
C PROGRAMMING
Stalongiles Philip
 
Introduction to c programming
Akshay Ithape
 
Introduction to c programming
Alpana Gupta
 
Learning the C Language
nTier Custom Solutions
 
Computer programming chapter ( 3 )
Ibrahim Elewah
 
C Language
Aakash Singh
 
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
Turbo C Compiler Reports
Sunil Kumar R
 
introduction to C programming (C)
Abhishek Walia
 
Brief introduction to the c programming language
Kumar Gaurav
 
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Programming in c
indra Kishor
 
C basics 4 std11(GujBoard)
indrasir
 
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
COM1407: Introduction to C Programming
Hemantha Kulathilake
 
Computer programming all chapters
Ibrahim Elewah
 
C programming basics
argusacademy
 

Similar to Introduction of c language (20)

PPTX
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
PPTX
C Programming UNIT 1.pptx
Mugilvannan11
 
PDF
Introduction to C Programming | Importance of Learning C
ShehanNadeesha
 
PPTX
C for Engineers
Julie Iskander
 
PPTX
C programming
Rohan Gajre
 
PDF
Introduction to C programming
Kathmandu University
 
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
PPTX
C PROGRAMMING AND DATA STRUCTURE _PPT.pptx
Prabu P
 
PPTX
Unit-1_c.pptx you from the heart of the day revision
MohammedAnas871930
 
PDF
Basics of C Prog Lang.pdf
KalighatOkira
 
PPT
C_Intro.ppt
gitesh_nagar
 
PPTX
chapter 1.pptx
SeethaDinesh
 
PPTX
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
PPTX
Introduction to C programming
Rokonuzzaman Rony
 
PPTX
Introduction to C Programming
Anandhasilambarasan D
 
PPT
8844632.ppt
SushmaG48
 
PPTX
Programming Fundamentals lecture 5
REHAN IJAZ
 
PPTX
1.1 programming fundamentals
Jawad Khan
 
PDF
88 c programs 15184
Sumit Saini
 
PDF
88 c-programs
Minh Thắng Trần
 
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
C Programming UNIT 1.pptx
Mugilvannan11
 
Introduction to C Programming | Importance of Learning C
ShehanNadeesha
 
C for Engineers
Julie Iskander
 
C programming
Rohan Gajre
 
Introduction to C programming
Kathmandu University
 
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
C PROGRAMMING AND DATA STRUCTURE _PPT.pptx
Prabu P
 
Unit-1_c.pptx you from the heart of the day revision
MohammedAnas871930
 
Basics of C Prog Lang.pdf
KalighatOkira
 
C_Intro.ppt
gitesh_nagar
 
chapter 1.pptx
SeethaDinesh
 
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
Introduction to C programming
Rokonuzzaman Rony
 
Introduction to C Programming
Anandhasilambarasan D
 
8844632.ppt
SushmaG48
 
Programming Fundamentals lecture 5
REHAN IJAZ
 
1.1 programming fundamentals
Jawad Khan
 
88 c programs 15184
Sumit Saini
 
88 c-programs
Minh Thắng Trần
 
Ad

More from farishah (6)

PDF
INTRODUCTION TO HARDWARE
farishah
 
PDF
Introduction to computer
farishah
 
PDF
Computer applications to business
farishah
 
PDF
Types of software
farishah
 
PDF
Algorithm
farishah
 
PPTX
Letter writing essentials
farishah
 
INTRODUCTION TO HARDWARE
farishah
 
Introduction to computer
farishah
 
Computer applications to business
farishah
 
Types of software
farishah
 
Algorithm
farishah
 
Letter writing essentials
farishah
 
Ad

Recently uploaded (20)

PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 

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.
  • 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.