SlideShare a Scribd company logo
1 of 32
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 

More Related Content

What's hot

What's hot (20)

Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C language
C languageC language
C language
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Tokens_C
Tokens_CTokens_C
Tokens_C
 
Chapter3
Chapter3Chapter3
Chapter3
 
C Language
C LanguageC Language
C Language
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Basic c
Basic cBasic c
Basic c
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 
C language introduction
C language introduction C language introduction
C language introduction
 
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
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
C tutorial
C tutorialC tutorial
C tutorial
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 

Similar to Introduction to C Unit 1

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).pptxrajkumar490591
 
C programming course material
C programming course materialC programming course material
C programming course materialRanjitha Murthy
 
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 REDDYRajeshkumar Reddy
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta 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
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
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.pdfComedyTechnology
 
(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.pptatulchaudhary821
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 

Similar to Introduction to C Unit 1 (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
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
 
C programming course material
C programming course materialC programming course material
C programming course material
 
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
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
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)
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
C tutorials
C tutorialsC tutorials
C tutorials
 
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
 
(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 languageC language
C language
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
c.ppt
c.pptc.ppt
c.ppt
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 

More from 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 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI 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)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI 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).pptxSURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 

More from SURBHI SAROHA (20)

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
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
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)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
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
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

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