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 

More Related Content

What's hot (20)

PPTX
Introduction to C Programming
Aniket Patne
 
PPT
C language
spatidar0
 
DOCX
C LANGUAGE NOTES
Malikireddy Bramhananda Reddy
 
PPT
Tokens_C
Prabhu Govind
 
PPT
Chapter3
Kamran
 
PPT
C Language
Aakash Singh
 
PPSX
C language (Collected By Dushmanta)
Dushmanta Nath
 
DOC
Basic c
Veera Karthi
 
PPT
Introduction to c programming
gajendra singh
 
PPT
Introduction to C Programming - I
vampugani
 
PPT
C language introduction
musrath mohammad
 
PPT
Brief introduction to the c programming language
Kumar Gaurav
 
DOCX
Features of c language 1
srmohan06
 
DOC
1. introduction to computer
Shankar Gangaju
 
ODP
OpenGurukul : Language : C Programming
Open Gurukul
 
DOC
C notes for exam preparation
Lakshmi Sarvani Videla
 
PPT
C PROGRAMMING
Stalongiles Philip
 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
 
PPTX
Programming in C Basics
Bharat Kalia
 
Introduction to C Programming
Aniket Patne
 
C language
spatidar0
 
Tokens_C
Prabhu Govind
 
Chapter3
Kamran
 
C Language
Aakash Singh
 
C language (Collected By Dushmanta)
Dushmanta Nath
 
Basic c
Veera Karthi
 
Introduction to c programming
gajendra singh
 
Introduction to C Programming - I
vampugani
 
C language introduction
musrath mohammad
 
Brief introduction to the c programming language
Kumar Gaurav
 
Features of c language 1
srmohan06
 
1. introduction to computer
Shankar Gangaju
 
OpenGurukul : Language : C Programming
Open Gurukul
 
C notes for exam preparation
Lakshmi Sarvani Videla
 
C PROGRAMMING
Stalongiles Philip
 
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Programming in C Basics
Bharat Kalia
 

Similar to Introduction to C Unit 1 (20)

PPTX
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
PPTX
Chapter1.pptx
SREEVIDYAP10
 
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
PPTX
unit 1 cpds.pptx
madhurij54
 
PPTX
C introduction by thooyavan
Thooyavan Venkatachalam
 
PDF
qb unit2 solve eem201.pdf
Yashsharma304389
 
DOCX
UNIT-II CP DOC.docx
JavvajiVenkat
 
PPTX
Basics of c Nisarg Patel
TechNGyan
 
PPTX
C language (1).pptxC language (1C language (1).pptx).pptx
RutviBaraiya
 
DOCX
Report on c and c++
oggyrao
 
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
PPTX
Introduction to C programming
Rutvik Pensionwar
 
PPTX
Unit No 2.pptx Basic s of C Programming
Vaibhav Parjane
 
PDF
Library management system
SHARDA SHARAN
 
PPT
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
PPTX
C for Engineers
Julie Iskander
 
PPT
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
PPTX
1_Introduction of programming language C.pptx
b221382
 
PPTX
Introduction to c
amol_chavan
 
PPTX
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
Chapter1.pptx
SREEVIDYAP10
 
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
unit 1 cpds.pptx
madhurij54
 
C introduction by thooyavan
Thooyavan Venkatachalam
 
qb unit2 solve eem201.pdf
Yashsharma304389
 
UNIT-II CP DOC.docx
JavvajiVenkat
 
Basics of c Nisarg Patel
TechNGyan
 
C language (1).pptxC language (1C language (1).pptx).pptx
RutviBaraiya
 
Report on c and c++
oggyrao
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
Introduction to C programming
Rutvik Pensionwar
 
Unit No 2.pptx Basic s of C Programming
Vaibhav Parjane
 
Library management system
SHARDA SHARAN
 
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
C for Engineers
Julie Iskander
 
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
1_Introduction of programming language C.pptx
b221382
 
Introduction to c
amol_chavan
 
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Ad

More from Dr. SURBHI SAROHA (20)

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

Recently uploaded (20)

PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
community health nursing question paper 2.pdf
Prince kumar
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 

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