SlideShare a Scribd company logo
Introduction to ‘C’
(UNIT 1)
BY:SURBHI SAROHA
Syllabus
 Overview of programming
 Program control flow
 Importance of C
 Structure of C functions
 Data Types
 Standard Input-Output functions
 Conditional statements
Overview of programming
 C is a general-purpose, high-level language that was originally developed by
Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was
originally first implemented on the DEC PDP-11 computer in 1972.
 In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available
description of C, now known as the K&R standard.
 The UNIX operating system, the C compiler, and essentially all UNIX application
programs have been written in C. C has now become a widely used professional
language for various reasons −
 Easy to learn
 Structured language
 It produces efficient programs
 It can handle low-level activities
 It can be compiled on a variety of computer platforms
Facts about C
 C was invented to write an operating system called UNIX.
 C is a successor of B language which was introduced around the early 1970s.
 The language was formalized in 1988 by the American National Standard
Institute (ANSI).
 The UNIX OS was totally written in C.
 Today C is the most widely used and popular System Programming Language.
 Most of the state-of-the-art software have been implemented using C.
 Today's most popular Linux OS and RDBMS MySQL have been written in C.
Program control flow
 Control statements enable us to specify the flow of program control; ie, the
order in which the instructions in a program must be executed. They make it
possible to make decisions, to perform tasks repeatedly or to jump from one
section of code to another.
 There are four types of control statements in C:
 Decision making statements
 Selection statements
 Iteration statements
 Jump statements
Importance of C
 As a middle-level language, C combines the features of both high-level and
low-level languages. It can be used for low-level programming, such as
scripting for drivers and kernels and it also supports functions of high-level
programming languages, such as scripting for software applications etc.
 C is a structured programming language which allows a complex program to
be broken into simpler programs called functions. It also allows free
movement of data across these functions.
 Various features of C including direct access to machine level hardware APIs,
the presence of C compilers, deterministic resource use and dynamic memory
allocation make C language an optimum choice for scripting applications and
drivers of embedded systems.
 C language is case-sensitive which means lowercase and uppercase letters are
treated differently.
Cont….
 C is highly portable and is used for scripting system applications which form a
major part of Windows, UNIX, and Linux operating system.
 C is a general-purpose programming language and can efficiently work on
enterprise applications, games, graphics, and applications requiring calculations,
etc.
 C language has a rich library which provides a number of built-in functions. It also
offers dynamic memory allocation.
 C implements algorithms and data structures swiftly, facilitating faster
computations in programs. This has enabled the use of C in applications requiring
higher degrees of calculations like MATLAB and Mathematica.Riding on these
advantages, C became dominant and spread quickly beyond Bell Labs replacing
many well-known languages of that time, such as ALGOL, B, PL/I, FORTRAN,
etc. C language has become available on a very wide range of platforms, from
embedded microcontrollers to supercomputers.
Structure of C functions
 A function is a group of statements that together perform a task. Every C program
has at least one function, which is main(), and all the most trivial programs can
define additional functions.
 You can divide up your code into separate functions. How you divide up your code
among different functions is up to you, but logically the division is such that each
function performs a specific task.
 A function declaration tells the compiler about a function's name, return type,
and parameters. A function definition provides the actual body of the function.
 The C standard library provides numerous built-in functions that your program can
call. For example, strcat() to concatenate two strings, memcpy() to copy one
memory location to another location, and many more functions.
 A function can also be referred as a method or a sub-routine or a procedure, etc.
Defining a Function
 The general form of a function definition in C programming language is as follows
−
 return_type function_name( parameter list ) {
 body of the function
 }
 A function definition in C programming consists of a function header and a
function body. Here are all the parts of a function −
 Return Type − A function may return a value. The return_type is the data type of
the value the function returns. Some functions perform the desired operations
without returning a value. In this case, the return_type is the keyword void.
 Function Name − This is the actual name of the function. The function name and
the parameter list together constitute the function signature.
Cont….
 Parameters − A parameter is like a placeholder. When a function is invoked,
you pass a value to the parameter. This value is referred to as actual
parameter or argument. The parameter list refers to the type, order, and
number of the parameters of a function. Parameters are optional; that is, a
function may contain no parameters.
 Function Body − The function body contains a collection of statements that
define what the function does.
Example
 Given below is the source code for a function called max(). This function takes two
parameters num1 and num2 and returns the maximum value between the two −
 /* function returning the max between two numbers */
 int max(int num1, int num2) {
 /* local variable declaration */
 int result;
 if (num1 > num2)
 result = num1;
 else
 result = num2;
 return result;
 }
Data Types
 A data type specifies the type of data that a variable can store such as
integer, floating, character, etc.
There are the following data types
in C language
Types Data Types
Basic Data Type int, char, float, double
Derived Data Type array, pointer, structure, union
Enumeration Data Type enum
Void Data Type void
Following are the examples of some very
common data types used in C:
 char: The most basic data type in C. It stores a single character and requires
a single byte of memory in almost all compilers.
 int: As the name suggests, an int variable is used to store an integer.
 float: It is used to store decimal numbers (numbers with floating point value)
with single precision.
 double: It is used to store decimal numbers (numbers with floating point
value) with double precision.
Standard Input-Output functions
 Input means to provide the program with some data to be used in the
program and Output means to display data on screen or write the data to a
printer or a file.
 C programming language provides many built-in functions to read any given
input and to display data on screen when there is a need to output the result.
 Before moving forward with input and output in C language, check these
topics out to understand the concept better :
 Data Types in C
 Variables in C
 Function in C
scanf() and printf() functions
 The standard input-output header file, named stdio.h contains the definition of
the functions printf() and scanf(), which are used to display output on screen and
to take input from user respectively.
 #include<stdio.h>
 void main()
 {
 // defining a variable
 int i;
 /*
 displaying message on the screen
 asking the user to input a value
 */
Cont….
 printf("Please enter a value...");
 /*
 reading the value entered by the user
 */
 scanf("%d", &i);
 /*
 displaying the number as output
 */
 printf( "nYou entered: %d", i);
 }
Cont….
Format String Meaning
%d Scan or print an integer as
signed decimal number
%f Scan or print a floating point
number
%c To scan or print a character
%s To scan or print a character
string. The scanning ends at
whitespace.
getchar() & putchar() functions
 The getchar() function reads a character from the terminal and returns it as
an integer.
 This function reads only single character at a time.
 You can use this method in a loop in case you want to read more than one
character.
 The putchar() function displays the character passed to it on the screen and
returns the same character.
 This function too displays only a single character at a time.
 In case you want to display more than one characters, use putchar() method
in a loop.
EXAMPLE
 #include <stdio.h>
 void main( )
 {
 int c;
 printf("Enter a character");
 /*
 Take a character as input and
 store it in variable c
 */
Cont…
 c = getchar();
 /*
 display the character stored
 in variable c
 */
 putchar(c);
 }
gets() & puts() functions
 The gets() function reads a line from stdin(standard input) into the buffer
pointed to by str pointer, until either a terminating newline or EOF (end of
file) occurs. The puts() function writes the string str and a trailing newline to
stdout.
 str → This is the pointer to an array of chars where the C string is stored.
(Ignore if you are not able to understand this now.)
 #include<stdio.h>
 void main()
 {
 /* character array of length 100 */
 char str[100];
Cont….
 printf("Enter a string");
 gets( str );
 puts( str );
 getch();
 }
Conditional statements
 Conditional Statements in C programming are used to make decisions based
on the conditions.
 Conditional statements execute sequentially when there is no condition
around the statements.
 If you put some condition for a block of statements, the execution flow may
change based on the result evaluated by the condition.
 This process is called decision making in 'C.‘
 In 'C' programming conditional statements are possible with the help of the
following two constructs:
 1. If statement
 2. If-else statement
Cont….
 If statement
 It is one of the powerful conditional statement. If statement is responsible for
modifying the flow of execution of a program. If statement is always used
with a condition. The condition is evaluated first before executing any
statement inside the body of If. The syntax for if statement is as follows:
 if (condition)
 instruction;
 The condition evaluates to either true or false. True is always a non-zero
value, and false is a value that contains zero. Instructions can be a single
instruction or a code block enclosed by curly braces { }.
EXAMPLE
 #include<stdio.h>
 int main()
 {
 int num1=1;
 int num2=2;
 if(num1<num2) //test-condition
 {
 printf("num1 is smaller than num2");
 }
 return 0;
 }
OUTPUT
 num1 is smaller than num2
The If-Else statement
The general form of if-else is as follows:
 if (test-expression)
 {
 True block of statements
 }
 Else
 {
 False block of statements
 }
 Statements;
EXAMPLE
 #include<stdio.h>
 int main()
 {
 int num=19;
 if(num<10)
 {
 printf("The value is less than 10");
 }
 else
 {
 printf("The value is greater than 10");
 }
 return 0;
 }
OUTPUT
 The value is greater than 10
THANK YOU 
Ad

More Related Content

What's hot (20)

Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Aniket Patne
 
C language
C languageC language
C language
spatidar0
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
Malikireddy Bramhananda Reddy
 
Tokens_C
Tokens_CTokens_C
Tokens_C
Prabhu Govind
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
C Language
C LanguageC Language
C Language
Aakash Singh
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
Dushmanta Nath
 
Basic c
Basic cBasic c
Basic c
Veera Karthi
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
gajendra singh
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
vampugani
 
C language introduction
C language introduction C language introduction
C language introduction
musrath mohammad
 
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
Kumar Gaurav
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
srmohan06
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
Lakshmi Sarvani Videla
 
C tutorial
C tutorialC tutorial
C tutorial
Chukka Nikhil Chakravarthy
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
Stalongiles Philip
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 

Similar to Introduction to C Unit 1 (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
C programming course material
C programming course materialC programming course material
C programming course material
Ranjitha Murthy
 
introductiontocprogramming-130719083552-phpapp01.ppt
introductiontocprogramming-130719083552-phpapp01.pptintroductiontocprogramming-130719083552-phpapp01.ppt
introductiontocprogramming-130719083552-phpapp01.ppt
RutviBaraiya
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
UNIT 5  C PROGRAMMING, PROGRAM STRUCTUREUNIT 5  C PROGRAMMING, PROGRAM STRUCTURE
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
C programming introduction for beginners.pdf
C programming introduction for beginners.pdfC programming introduction for beginners.pdf
C programming introduction for beginners.pdf
sagarduari1
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
Vishwas459764
 
C tutorials
C tutorialsC tutorials
C tutorials
Amit Kapoor
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
aaravSingh41
 
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
 
(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
atulchaudhary821
 
C language
C languageC language
C language
marar hina
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
Durga Padma
 
C programming notes
C programming notesC programming notes
C programming notes
Prof. Dr. K. Adisesha
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
C programming course material
C programming course materialC programming course material
C programming course material
Ranjitha Murthy
 
introductiontocprogramming-130719083552-phpapp01.ppt
introductiontocprogramming-130719083552-phpapp01.pptintroductiontocprogramming-130719083552-phpapp01.ppt
introductiontocprogramming-130719083552-phpapp01.ppt
RutviBaraiya
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
UNIT 5  C PROGRAMMING, PROGRAM STRUCTUREUNIT 5  C PROGRAMMING, PROGRAM STRUCTURE
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
C programming introduction for beginners.pdf
C programming introduction for beginners.pdfC programming introduction for beginners.pdf
C programming introduction for beginners.pdf
sagarduari1
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
Vishwas459764
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
aaravSingh41
 
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
 
(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
atulchaudhary821
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
Ad

More from Dr. SURBHI SAROHA (20)

Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
Dr. SURBHI SAROHA
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
Dr. SURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
Dr. SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
Dr. SURBHI SAROHA
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
Dr. SURBHI SAROHA
 
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Ad

Recently uploaded (20)

What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 

Introduction to C Unit 1

  • 1. Introduction to ‘C’ (UNIT 1) BY:SURBHI SAROHA
  • 2. Syllabus  Overview of programming  Program control flow  Importance of C  Structure of C functions  Data Types  Standard Input-Output functions  Conditional statements
  • 3. Overview of programming  C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.  In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.  The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons −  Easy to learn  Structured language  It produces efficient programs  It can handle low-level activities  It can be compiled on a variety of computer platforms
  • 4. Facts about C  C was invented to write an operating system called UNIX.  C is a successor of B language which was introduced around the early 1970s.  The language was formalized in 1988 by the American National Standard Institute (ANSI).  The UNIX OS was totally written in C.  Today C is the most widely used and popular System Programming Language.  Most of the state-of-the-art software have been implemented using C.  Today's most popular Linux OS and RDBMS MySQL have been written in C.
  • 5. Program control flow  Control statements enable us to specify the flow of program control; ie, the order in which the instructions in a program must be executed. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.  There are four types of control statements in C:  Decision making statements  Selection statements  Iteration statements  Jump statements
  • 6. Importance of C  As a middle-level language, C combines the features of both high-level and low-level languages. It can be used for low-level programming, such as scripting for drivers and kernels and it also supports functions of high-level programming languages, such as scripting for software applications etc.  C is a structured programming language which allows a complex program to be broken into simpler programs called functions. It also allows free movement of data across these functions.  Various features of C including direct access to machine level hardware APIs, the presence of C compilers, deterministic resource use and dynamic memory allocation make C language an optimum choice for scripting applications and drivers of embedded systems.  C language is case-sensitive which means lowercase and uppercase letters are treated differently.
  • 7. Cont….  C is highly portable and is used for scripting system applications which form a major part of Windows, UNIX, and Linux operating system.  C is a general-purpose programming language and can efficiently work on enterprise applications, games, graphics, and applications requiring calculations, etc.  C language has a rich library which provides a number of built-in functions. It also offers dynamic memory allocation.  C implements algorithms and data structures swiftly, facilitating faster computations in programs. This has enabled the use of C in applications requiring higher degrees of calculations like MATLAB and Mathematica.Riding on these advantages, C became dominant and spread quickly beyond Bell Labs replacing many well-known languages of that time, such as ALGOL, B, PL/I, FORTRAN, etc. C language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.
  • 8. Structure of C functions  A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.  You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division is such that each function performs a specific task.  A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.  The C standard library provides numerous built-in functions that your program can call. For example, strcat() to concatenate two strings, memcpy() to copy one memory location to another location, and many more functions.  A function can also be referred as a method or a sub-routine or a procedure, etc.
  • 9. Defining a Function  The general form of a function definition in C programming language is as follows −  return_type function_name( parameter list ) {  body of the function  }  A function definition in C programming consists of a function header and a function body. Here are all the parts of a function −  Return Type − A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.  Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • 10. Cont….  Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.  Function Body − The function body contains a collection of statements that define what the function does.
  • 11. Example  Given below is the source code for a function called max(). This function takes two parameters num1 and num2 and returns the maximum value between the two −  /* function returning the max between two numbers */  int max(int num1, int num2) {  /* local variable declaration */  int result;  if (num1 > num2)  result = num1;  else  result = num2;  return result;  }
  • 12. Data Types  A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
  • 13. There are the following data types in C language Types Data Types Basic Data Type int, char, float, double Derived Data Type array, pointer, structure, union Enumeration Data Type enum Void Data Type void
  • 14. Following are the examples of some very common data types used in C:  char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.  int: As the name suggests, an int variable is used to store an integer.  float: It is used to store decimal numbers (numbers with floating point value) with single precision.  double: It is used to store decimal numbers (numbers with floating point value) with double precision.
  • 15. Standard Input-Output functions  Input means to provide the program with some data to be used in the program and Output means to display data on screen or write the data to a printer or a file.  C programming language provides many built-in functions to read any given input and to display data on screen when there is a need to output the result.  Before moving forward with input and output in C language, check these topics out to understand the concept better :  Data Types in C  Variables in C  Function in C
  • 16. scanf() and printf() functions  The standard input-output header file, named stdio.h contains the definition of the functions printf() and scanf(), which are used to display output on screen and to take input from user respectively.  #include<stdio.h>  void main()  {  // defining a variable  int i;  /*  displaying message on the screen  asking the user to input a value  */
  • 17. Cont….  printf("Please enter a value...");  /*  reading the value entered by the user  */  scanf("%d", &i);  /*  displaying the number as output  */  printf( "nYou entered: %d", i);  }
  • 18. Cont…. Format String Meaning %d Scan or print an integer as signed decimal number %f Scan or print a floating point number %c To scan or print a character %s To scan or print a character string. The scanning ends at whitespace.
  • 19. getchar() & putchar() functions  The getchar() function reads a character from the terminal and returns it as an integer.  This function reads only single character at a time.  You can use this method in a loop in case you want to read more than one character.  The putchar() function displays the character passed to it on the screen and returns the same character.  This function too displays only a single character at a time.  In case you want to display more than one characters, use putchar() method in a loop.
  • 20. EXAMPLE  #include <stdio.h>  void main( )  {  int c;  printf("Enter a character");  /*  Take a character as input and  store it in variable c  */
  • 21. Cont…  c = getchar();  /*  display the character stored  in variable c  */  putchar(c);  }
  • 22. gets() & puts() functions  The gets() function reads a line from stdin(standard input) into the buffer pointed to by str pointer, until either a terminating newline or EOF (end of file) occurs. The puts() function writes the string str and a trailing newline to stdout.  str → This is the pointer to an array of chars where the C string is stored. (Ignore if you are not able to understand this now.)  #include<stdio.h>  void main()  {  /* character array of length 100 */  char str[100];
  • 23. Cont….  printf("Enter a string");  gets( str );  puts( str );  getch();  }
  • 24. Conditional statements  Conditional Statements in C programming are used to make decisions based on the conditions.  Conditional statements execute sequentially when there is no condition around the statements.  If you put some condition for a block of statements, the execution flow may change based on the result evaluated by the condition.  This process is called decision making in 'C.‘  In 'C' programming conditional statements are possible with the help of the following two constructs:  1. If statement  2. If-else statement
  • 25. Cont….  If statement  It is one of the powerful conditional statement. If statement is responsible for modifying the flow of execution of a program. If statement is always used with a condition. The condition is evaluated first before executing any statement inside the body of If. The syntax for if statement is as follows:  if (condition)  instruction;  The condition evaluates to either true or false. True is always a non-zero value, and false is a value that contains zero. Instructions can be a single instruction or a code block enclosed by curly braces { }.
  • 26. EXAMPLE  #include<stdio.h>  int main()  {  int num1=1;  int num2=2;  if(num1<num2) //test-condition  {  printf("num1 is smaller than num2");  }  return 0;  }
  • 27. OUTPUT  num1 is smaller than num2
  • 29. The general form of if-else is as follows:  if (test-expression)  {  True block of statements  }  Else  {  False block of statements  }  Statements;
  • 30. EXAMPLE  #include<stdio.h>  int main()  {  int num=19;  if(num<10)  {  printf("The value is less than 10");  }  else  {  printf("The value is greater than 10");  }  return 0;  }
  • 31. OUTPUT  The value is greater than 10
  翻译: