SlideShare una empresa de Scribd logo
1 de 47
Introduction to C language
2
Reference Books
 Let Us C by Yashavant P. Kanetkar
 Turbo C by Robert Lafore
3
What is a Program?
 A Precise sequence of steps to solve a
particular problem.
 Precise=exact
 Sequence= what should be first, what should be
second, and so on..
 And there should be any problem to solve.
4
What is a programming
Language?
 A vocabulary and set of grammatical rules for
instructing a Computer to perform specific tasks.
Each language has a unique set of keywords
(words that it understands) and a special syntax
for organizing program instructions.
5
Introduction to C Language
 C is a programming language.
 It was developed at AT & T’s Bell
Laboratories of USA in 1972.
 It was designed and written by a man named
Dennis Ritchie.
Dennis Ritchie
6
Reasons to learn C
 Main reason is its simplicity reliability, and
its easy to use and easy to learn
7
8
Some Definitions
 Syntax(form):- The syntax of a language
describes the possible combinations of symbols
that form a correct program.
 IDE:- It is a screen display with pull down
menus. We use menu selections to invoke all
the operations necessary to develop our
program.
9
Some Definitions
 Compiler:- It is the part of IDE, that translates our
source file into machine language.
 Keyword:- Keywords are the words whose
meaning has already been explained to the C
compiler
10
My first Program
#include<stdio.h>
void main(void)
{
printf(“How are you!”);
}
11
12
Output
How are you!
13
What is #include<stdio.h> ?
 Since we are using a function printf(); in our program in order to
print a sentence, so it is necessary to give reference of this function.
 The functionality of printf(); function is defined somewhere in one
of many C Standard Libraries, the name of that library is stdio.h.
 Hence including stdio.h at the top of our program become reference
for printf function. We also call it prototype, or header file, since it
is at the head of our program.
 stdio.h, which stands for "standard input/output header", is the
header in the C standard library that contains definitions, constants,
and declarations of functions and types used for various standard
input and output operations.
14
What is void main(void)?
 C language is function oriented language. In this
language we write programs through functions.
 C provides some built-in functions. We call it built-
in, because functions can also be user defined, which
we will learn later in this course.
 Hence main is one of the functions of C. Its name is
main, because it is an important function, and must be
used in a C program, whether you are using other
functions or not.
15
What is void main(void)?
Cont..
 Void which is written before main means that the
function main will not return a value.
 Void which is written after main means that the
function main will not send any argument.
.
16
More on main()….
 This is the entry point of a program
 When a file is executed, the start point is the main
function
 From main function the flow goes as per the
programmers choice.
 There may or may not be other functions written
by user in a program
 Main function is compulsory for any c program
17
#include<stdio.h>
#include<conio.h>
void main(void)
{
printf(“How are you!”);
getch();
}
18
Explanation:
Note that, we have written an extra function:
“getch();”.
This function holds the output ”How are you” on the
output window, till user presses any key. Getch stands
for get character.
Getch() fucntion is the member of conio.h library, hence
we include this library at the top of our program.
19
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“How are you!”);
getch();
}
20
What is clrscr(); ?
 Clrscr(); is a fucntion used to clear the
previous output from output window.
21
My second Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“4 is a number”);
getch();
}
22
Output
4 is a number
23
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“4+4 is a number”);
getch();
}
24
Output
4+4 is a number
Explanation:
Since we are writing a number inside the double
quotes, it is treated as text, not a number. In order to
treat numbers as numbers, we use format specifiers
inside printf.
25
Escape Sequence
No. Syntax Application Example
1 n New Line printf(“n”);
2 t Tab eight spaces to right printf(“t”);
3 b
Back space One space
back
printf(“b”);
4 r
Carriage return Start of
same line
printf(“r”);
5 ’ Printing single quote printf(“’”);
6 ” Printing double quotes printf(“””);
7  Printing back space printf(“”);
26
No. Type Syntax Value Example
1 Single Character %c
One character within single
quotes
printf(“%c”,’a’);
2 String %s
A sentence of an unfixed
length within double quotes
printf(“%s”,”Iqra Univ”);
3 Decimal Integer %d
Any whole number between
-32,768 to 32,767
printf(“%d”,12345);
4 Long Integer %ld
Any number between
-2,147,483,648 to
2,147,483,647
printf(“%ld”,1234567);
5 Float %f
Any decimal point number
between 10-38
to 1038
printf(“%f”,1234.567);
6 Double %lf
Any decimal point number
between 10-308
to 10308
printf(“%lf”,12345678);
27
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“%d is a number”,4);
getch();
} OUTPUT (4 IS A NUMBER)
28
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“%d is a number”,4+4);
getch();
}
 OUTPUT (8 IS A NUMBER)
29
 %d is a format specifier, used to indicate
integers.
 Integer is a Data Type, used to represent
non decimal numbers.
30
Data types in C
 Primitive data types
 int, float, double, char
31
Variables
 Variables are data that will keep on changing
 Declaration
<<Data type>> <<variable name>>;
int a;
 Definition
<<varname>>=<<value>>;
a=10;
 Usage
<<varname>>
a=a+1; //increments the value of a by 1
32
Variable names- Rules
 Should not be a reserved word like int etc..
 Should start with a letter or an underscore(_)
 Can contain letters, numbers or underscore.
 No other special characters are allowed including
space
 Variable names are case sensitive
 A and a are different.
33
34
Rules for Constructing Integer
Constants
 An integer constant must have at least one digit.
 It must not have a decimal point.
 It can be either positive or negative.
 If no sign precedes an integer constant it is
assumed to be positive.
 No commas or blanks are allowed within an
integer constant.
 The allowable range for integer constants is -32768
to 32767.
35
How we use an Integer in C
Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d;
d=84;
printf(“%d is a number”,d);
getch();
} OUTPUT :84 IS A NUMBER:
36
 A constant is quantity, that doesn’t change.
 A variable can be considered as a name given to the
locationin memory, where this constant is stored.
d=84;
 In above instruction, d is a variable, and 84 is
constant.
37
 We can use mathematical manipulations/
calculations with integers, some of the examples
are given:
38
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d;
d=84+2;
printf(“%d is a number”,d);
getch();
} OUTPUT (86 IS A NUMBER)
39
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d;
d=84;
printf(“%d is a number”,d+2);
getch();
} OUTPUT (86 IS A NUMBER)
40
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d=84;
printf(“%d is a number”,d);
getch();
}
41
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d=84, e=50, f;
f=d+e;
printf(“%d is a number”,f);
getch();
}
 OUTPUT (134 IS A NUMBER)
42
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d=84, e=50, f;
f=d-e;
printf(“%d is a number”,f);
getch();
}
43
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int d=84, e=50, f;
f=d*e;
printf(“%d is a number”,f);
getch();
}
44
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
float d=84, e=50, f;
f=d/e;
printf(“%f is a number”,f);
getch();
}
45
Getting input from User
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int a;
printf(”Please type a number:”);
scanf(“%d”,&a);
printf(“You typed %d”, a);
getch();
}
46
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int a,b;
printf(”Please type two numbers:”);
scanf(“%d%d”,&a,&b);
printf(“You typed %d and %d”, a , b );
getch();
}
47
Task
 Write a Program, that gets input two numbers
from user, and calculates their sum.

Más contenido relacionado

La actualidad más candente

C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 

La actualidad más candente (20)

OOP in C++
OOP in C++OOP in C++
OOP in C++
 
C program
C programC program
C program
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C programming
C programmingC programming
C programming
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
C Programming
C ProgrammingC Programming
C Programming
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
C language introduction
C language introduction C language introduction
C language introduction
 
C language
C languageC language
C language
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
C programming language
C programming languageC programming language
C programming language
 

Destacado

Destacado (10)

hist1
 hist1 hist1
hist1
 
corona total metalica
 corona total metalica corona total metalica
corona total metalica
 
Convocatoria
ConvocatoriaConvocatoria
Convocatoria
 
UN-insure your teen driver
UN-insure your teen driverUN-insure your teen driver
UN-insure your teen driver
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
Flight dental systems a2 operatory presentation 2016 r.2
Flight dental systems a2 operatory presentation 2016 r.2Flight dental systems a2 operatory presentation 2016 r.2
Flight dental systems a2 operatory presentation 2016 r.2
 
Graph & Heap in Data Structure (Basic Information)
Graph & Heap in Data Structure (Basic Information)Graph & Heap in Data Structure (Basic Information)
Graph & Heap in Data Structure (Basic Information)
 
Revital vision стартовая для клиник
Revital vision стартовая для клиникRevital vision стартовая для клиник
Revital vision стартовая для клиник
 
Aanvraag QlikView Developer
Aanvraag QlikView DeveloperAanvraag QlikView Developer
Aanvraag QlikView Developer
 
4.3.1 total physical response tpr definitivo
4.3.1 total physical response   tpr definitivo4.3.1 total physical response   tpr definitivo
4.3.1 total physical response tpr definitivo
 

Similar a Lecture#5 c lang new

C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
ComedyTechnology
 

Similar a Lecture#5 c lang new (20)

(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
C language
C language C language
C language
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptx
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C Theory
C TheoryC Theory
C Theory
 
C notes
C notesC notes
C notes
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakil
 
Chapter3
Chapter3Chapter3
Chapter3
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
 
C programming
C programmingC programming
C programming
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Lecture#5 c lang new