Module 1 - Introduction to C Programming.pptm (1).pdf

SudipDebnath20 80 views 98 slides May 27, 2024
Slide 1
Slide 1 of 98
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98

About This Presentation

c programming


Slide Content

PRPEARED BY: PROF. NEHA HARDE ©
C PROGRAMMING
Module 1
Introduction to C Programming
Course Outcome (CO1):
Understand the basic syntax and semantics of C.

PRPEARED BY: PROF. NEHA HARDE ©
What is Computer ?
Characteristics of computer
Benefits of computer
Computer Components
Input Devices
Output Devices
Central Processing Unit
Memory Unit
Introduction to Components
of a computer system

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS COMPUTER ?
A computer is a programmable electronic
device that accepts raw data as input and
processes it with a set of instructions (a
program) to produce the result as output
The father of the
computer:
Charles Babbage

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS COMPUTER ?

PRPEARED BY: PROF. NEHA HARDE ©
CHARACTERISTICS OF COMPUTER
Speed Memory Accuracy Diligence Versatile
Multitask
ing

PRPEARED BY: PROF. NEHA HARDE ©
BENEFITS OF COMPUTER
Storage
Increases
Productivity
Connects
to the
Internet
Improves
ability
Provides
an
entertainm
ent
Organizes
data and
information

PRPEARED BY: PROF. NEHA HARDE ©
COMPUTER COMPONENTS

PRPEARED BY: PROF. NEHA HARDE ©
COMPUTER COMPONENTS
Input is any data or instruction given to the computer
Input device enables the user to send data, information, or control signals
to a computer
The prime purpose of input devices are to translate data and information
from human-readable format into electrical impulses
1.Input Devices

PRPEARED BY: PROF. NEHA HARDE ©
INPUT DEVICES
Keyboard is a basic input device that is
used to enter data into a computer or any
other electronic device by pressing keys
 Mouse is a pointing hand-held input
device which is used to move cursor or
pointer across the screen

PRPEARED BY: PROF. NEHA HARDE ©
Scanner scans the picture or a document
converts it into a digital format and is
displayed on the screen as an output
Joystick is a pointing input device like a
mouse and movement of stick controls the
cursor or pointer on the screen
INPUT DEVICES

PRPEARED BY: PROF. NEHA HARDE ©
Light pen is like a pen. The tip of the light
pen contains a light-sensitive detector that
enables the user to point to or select objects
on the display screen
Microphone is used to input the sound to
presentations and with webcams for video
conferencing
INPUT DEVICES

PRPEARED BY: PROF. NEHA HARDE ©
COMPUTER COMPONENTS
The output device displays the result of the processing of raw data that is
entered in the computer through an input device
It is used to bring out the information from the computer
2. Output Devices

PRPEARED BY: PROF. NEHA HARDE ©
Monitor is the display unit or screen of the
computer that displays the processed data or
information as text, images, audio or video
Printer is a device that prints text, images or
any information on paper producing hard
copy of the information
OUTPUT DEVICES

PRPEARED BY: PROF. NEHA HARDE ©
A projector is an output device that enables
the user to project the output onto a large
surface such as a big screen or wall
Speaker is an output device connected to a
computer's sound card that outputs sounds
generated by the computer
OUTPUT DEVICES

PRPEARED BY: PROF. NEHA HARDE ©
COMPUTER COMPONENTS
Brain of the computer system
It receives instructions from both the hardware and
active software and produces output accordingly
3. Central Processing Unit

PRPEARED BY: PROF. NEHA HARDE ©
CENTRAL PROCESSING UNIT (CPU)
Control Unit is used to control the entire working
of a computer system and it controls the transfer of
data between memory and input/output devices or
I/O devices
Arithmetic and Logic Unit is designed to
perform all the basic arithmetic operations and
logical operations

PRPEARED BY: PROF. NEHA HARDE ©
COMPUTER COMPONENTS
Memory unit is used to retain the program instruction and data for processing
Two types of memory:
Primary Memory
Secondary Memory
4. Memory Unit

PRPEARED BY: PROF. NEHA HARDE ©
MEMORY UNIT
Main memory of the computer
Directly accessed by the
 CPU
Volatile
Faster access
Semiconductor Memory - Expensive
Less storage capacity
Primary Memory

PRPEARED BY: PROF. NEHA HARDE ©
Primary Memory
MEMORY UNIT

PRPEARED BY: PROF. NEHA HARDE ©
Primary Memory
MEMORY UNIT

PRPEARED BY: PROF. NEHA HARDE ©
External Memory
High storage capacity
Permanent storage
Non volatile
Slower access
Magnetic or optical memory - Less Expensive
Secondary Memory
MEMORY UNIT

PRPEARED BY: PROF. NEHA HARDE ©
MEMORY UNIT

PRPEARED BY: PROF. NEHA HARDE ©
What is Algorithm ?
Characteristics of algorithm
How to write an algorithm ?
Flowchart
Flowchart Symbols
How to draw a flowchart ?
Introduction to Algorithm
and Flowchart

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS ALGORITHM
An algorithm can be defined as a finite set of steps, which has to be followed
while carrying out a particular problem
An algorithm is a distinct computational procedure that takes input as a set of
values and results in the output as a set of values by solving the problem

PRPEARED BY: PROF. NEHA HARDE ©
CHARACTERISTICS OF ALGORITHM
•Well defined zero or more inputs Input
•Generate at least one output Output
•Each Instruction should be clear Unambiguous
•Algorithm should terminate after executing
finite no. of instructions
Finiteness
•Every instruction should be fundamental to be
carried out, in principle
Effectiveness

PRPEARED BY: PROF. NEHA HARDE ©
HOW TO WRITE AN ALGORITHM
Step 1: Start
Step 2: Read values num1 and num2.
Step 3: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step4: Display sum
Step 5: Stop
Example: Add two numbers

PRPEARED BY: PROF. NEHA HARDE ©
HOW TO WRITE AN ALGORITHM
Step 1: Start
Step 2: Read variables a, b and c.
Step 3: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 4: Stop
Example:
 Find the largest number among three numbers

PRPEARED BY: PROF. NEHA HARDE ©
FLOWCHART
A flowchart is a visual representation of the sequence
of steps and decisions needed to perform a process
A flowchart is a powerful business tool - With proper
design and construction, it communicates the steps in
a process very effectively and efficiently.

PRPEARED BY: PROF. NEHA HARDE ©
FLOWCHART SYMBOLS

PRPEARED BY: PROF. NEHA HARDE ©
HOW TO DRAW A FLOWCHART
Example: Add two numbers
Step 1: Start
Step 2: Read values num1 and num2.
Step 3: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 5: Stop

PRPEARED BY: PROF. NEHA HARDE ©
HOW TO DRAW A FLOWCHART
Example:
 Find the largest number among three numbers
Start
Input a, b, c
Is
a>b ?
Is a>c
?
Yes
Is b>c
?
No
Print a is the
largest number
Yes
Print c is the
largest number
NoNo
Print b is the
largest number
Yes
End

PRPEARED BY: PROF. NEHA HARDE ©
What is Programming Language ?
Types of Programming Languages
What is Compiler ?
What is Interpreter ?
Compiler Vs Interpreter
C Programming Language
Features of C
Applications of C
C Program Structure
Compilation Process
Introduction to C Programming

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS PROGRAMMING LANGUAGE
A programming language is a
 computer language that is used
by
 programmers (developers) to communicate with computers

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF PROGRAMMING LANGUAGES
Low Level Programming Language
High Level Programming Language
Middle Level Programming Language
Machine Dependent
Runs without the need of compiler and interpreter
Example: 0 1 (Binary)
User friendly
Used to develop applications, websites
Requires compiler and interpreter
Example: Python, C, C++, Java
Related to both high level and Machine level
languages
Requires Assembler
Example: Assembly Language

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF PROGRAMMING LANGUAGES

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS COMPILER ?
A compiler is a computer program that transforms code written
in a high-level programming language into the machine code

PRPEARED BY: PROF. NEHA HARDE ©
WHAT IS INTERPRETER ?
An interpreter is a computer program, which coverts each
high-level program statement into the machine code.

PRPEARED BY: PROF. NEHA HARDE ©
COMPILER VS INTERPRETER

PRPEARED BY: PROF. NEHA HARDE ©
COMPILER VS INTERPRETER

PRPEARED BY: PROF. NEHA HARDE ©
C PROGRAMMING LANGUAGE
 C
 is a general-purpose, structured programming language
that is extremely popular, simple, and flexible to use
Developed in 1972 by Dennis Ritchie at bell laboratories of
AT&T, located in the U.S.A.
Mother of Programming Languages - C programming is
considered as the base for other programming languages

PRPEARED BY: PROF. NEHA HARDE ©
FEATURES OF C

PRPEARED BY: PROF. NEHA HARDE ©
APPLICATIONS OF C

PRPEARED BY: PROF. NEHA HARDE ©
C PROGRAM STRUCTURE
/* C program to Print Hello World */
#include<stdio.h>
#define MAX 10
int a = 20;
int main()
{
printf(“Hello World”);
printf(“a = %d”, a);
return 0;
}

PRPEARED BY: PROF. NEHA HARDE ©
COMPILATION PROCESS

PRPEARED BY: PROF. NEHA HARDE ©
Constants
Keywords
Identifiers
Variables
Types of Variables
Data Types
Operators
Unary Operators
Binary Operators
Ternary Operators
Operator Precedence
Operator Associativity
Input and Output Functions
Format Specifiers
Formatted I/O Functions
 Unformatted I/O Functions
Basics of C

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
Constants or literals are like variables, but their values are
fixed
Once defined, value of the constant cannot be changed

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
1. Numeric Constants
Integer Constants: Sequence of digits
•Decimal Integer
Example:
12250 -4500 0
•Octal Integer
Example:
05 0632
•Hexadecimal Integer
Example:
0X6A 0x79BD 0X346
Rules for Constructing Integer Constants:
An Integer constant must have at least one
digit
It can be either positive or negative
No commas or blanks or special symbols are
allowed
Allowable range is -32768 to 32767

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
1. Numeric Constants
Real Constants: (Floating point constants)
Numbers having fractional part
Example:
34.89 -22.1845 +0.76
Exponential Representation of Real Constants:
Example:
6.78e3 -0.45E-4
Rules for Constructing Real Constants:
An real constant must have at least one digit
and decimal point
It can be either positive or negative
No commas or blanks or special symbols are
allowed
Mantissa Exponent

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
2. Character Constants
Single Character Constants:
Single character or Single Digit or Single Special
Symbol enclosed within single inverted commas
Example:
‘A’ ‘m’ ‘8’ ‘@’
Note: 8 ≠ ‘8’
Rules for Constructing Single Character Constants:
Length of character constant can be 1 character
Character constant should be in single inverted
commas

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
2. Character Constants
String Constants:
Sequence of characters enclosed within double quotes
Example:
“college” “m” “a8bn”
Note:
1. ‘a’ ≠ “a”
2. Compiler will add ‘\0’ (null character at the end of
the string
Rules for Constructing String Constants:
String constants should be enclosed within
double quotes
String constants can be of any length
String constant ends with a null character
assigned to it by the compiler

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
2. Character Constants
Backslash Character Constants: (Escape Sequences)
Backslash characters have a specific meaning which is
known to the compiler

PRPEARED BY: PROF. NEHA HARDE ©
CONSTANTS IN C
Defining Constant
1.Using const Keyword
Syntax:
const data_type constant_name = value;
Example:
const int A = 10;
2. Using #define pre-processor
Syntax:
#define const_name value
Example:
#define PI 3.14
Two ways to define constants

PRPEARED BY: PROF. NEHA HARDE ©
KEYWORDS IN C
Keywords are the reserved words having specific
meaning defined to the compiler
32 Keywords in C
Keywords cannot be used as a variable names

PRPEARED BY: PROF. NEHA HARDE ©
KEYWORDS IN C

PRPEARED BY: PROF. NEHA HARDE ©
IDENTIFIERS IN C
Identifiers represent the name in the C program; Like names of
variables, functions, arrays, structures, unions, labels
Note:
C is a case
sensitive language
Sum ≠ sum

PRPEARED BY: PROF. NEHA HARDE ©
IDENTIFIERS IN C
Rules for Constructing String Constants:
An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits)
and underscore( _ ) symbol.
Identifier names must be unique
The first character must be an alphabet or underscore.
You cannot use a keyword as identifiers.
Only the first thirty-one (31) characters are significant.
It must not contain white spaces.
Identifiers are case-sensitive.

PRPEARED BY: PROF. NEHA HARDE ©
VARIABLES IN C
A
 variable is a name given to the memory location where
data is stored depending upon the type of the variable
Variable Declaration:
Syntax:
data_type variable_name;
Example:
int choice;
char ans;
10 20
5 ‘a’
n1
chn3
n2
100
200140
104

PRPEARED BY: PROF. NEHA HARDE ©
VARIABLES IN C
Variable Initialization:
Variable initialization means
 assigning some value to that variable
Example:
int ch;
ch = 10;
OR
Variable Declaration and initialization on the same line
int ch = 10;

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES
1. Local Variables
A variable that is declared inside the function or block is called a local variable
Scope: Lies within the function or block of code
Life: Stay in the memory till the end of the program
Example:
void fun1()
{
int lv = 20;
printf(“value = %d”, lv);
}

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES
2. Global Variables
A variable that is declared outside the function or block is called a global variable
Value of global variable can be changed by any function
Scope: Available to all functions
Life: Stay in the memory till the end of the program
Example:
int gv = 10;
void fun1()
{
int lv = 20;
printf(“value of lv = %d \n value of gv= %d ”, lv, gv);
}

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES
3. Static Variables
A variable declared with static keyword which retains its value within the function calls is
called as static variable
Cannot be initialized again
Scope: Local to the function or block
Life: Value retains within the function calls
Example:
static int a = 11;

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES
4. Automatic Variables
All variables in C that are declared inside the block, are automatic variables by default
Explicit declaration using auto keyword
Scope: Local to the function or block
Life: Till the end of the block
Example:
void fun1()
{
int a = 10; // Automatic
auto int b = 20;
}

PRPEARED BY: PROF. NEHA HARDE ©
TYPES OF VARIABLES
5. External Variables
We can share a variable in multiple C source files by using an external variable
extern keyword is used
Scope: Global in other files too
Life: Till the end of the program
Example:
extern int a;
Pro1.c
extern int a = 10;
Pro2.c
#include<stdio.h>
#include “pro1.h”

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C
Data types refer to the characteristics of data stored into a variable
Data type helps you find Size, range and type of value
C Data Types are used to:
Identify the type of a variable when it declared
Identify the type of the return value of a function
Identify the type of a parameter expected by a function
10 20
5 ‘a’
n1
chn3
n2
100
200140
104

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C
Primitive Data Types
2
??????????????????−1

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C
Primitive Data Types

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C
Primitive Data Types
2
??????????????????
−1

PRPEARED BY: PROF. NEHA HARDE ©
DATATYPES IN C
Primitive Data Types

PRPEARED BY: PROF. NEHA HARDE ©
OPERATORS IN C
C operators are symbols that are used to perform mathematical or logical manipulation
 The C programming language is rich with built-in operators
Operators take part in a program for manipulating data and variables and form a part of
the mathematical or logical expressions
Mathematical Expression:

PRPEARED BY: PROF. NEHA HARDE ©
OPERATORS IN C
Operators are symbols or a set of symbols that change or assign values, combine
values, or check or verify values in your code
Types of Operators:
1.Unary Operator
2.Binary Operator
3.Ternary Operator

PRPEARED BY: PROF. NEHA HARDE ©
UNARY OPERATORS
Unary Operators are the operators which require single operand to perform any action
1.Sizeof
2.Unary minus
3.Logical NOT
4.Increment
5.Decrement
6.& (Addrss of)
7.* (Value of)

PRPEARED BY: PROF. NEHA HARDE ©
UNARY OPERATORS
Unary Operators are the operators which require single operand to perform any action
1.sizeof: return the size of an operand in bytes (prefix Operator)
Example: sizeof(operand)
2. unary minus: it negates a value (Prefix Operator)
Example: a = -10;
b = -a;
3. Logical NOT: The logical NOT operator inverts the value of a Boolean variable (Prefix Operator)
Example: c = True
a = !c;

PRPEARED BY: PROF. NEHA HARDE ©
UNARY OPERATORS
Unary Operators are the operators which require single operand to perform any action
4. Increment: (Prefix and Postfix)
Increment : ++ (increases a numeric value by 1) a = a + 1
a)Post Increment:
Example: a++
b)Pre Increment:
Example: ++a

PRPEARED BY: PROF. NEHA HARDE ©
UNARY OPERATORS
Unary Operators are the operators which require single operand to perform any action
5. Decrement: (Postfix and Prefix)
Decrement: -- (decreases a numeric value by 1) a = a – 1
a)Post Decrement:
Example: a--
b)Pre Decrement:
Example: --a

PRPEARED BY: PROF. NEHA HARDE ©
UNARY OPERATORS
Unary Operators are the operators which require single operand to perform any action
6. & (Address of): Returns the address of a variable (Prefix Operator)
Example: &a
7. * (Value of): Returns value stored at the address (Works with pointers)
Example: *a

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
Binary Operators are the operators which require two operands to perform any action
1.Arithmetic
2.Relational
3.Logical
4.Bitwise
5.Assignment

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
1.Arithmetic Operators: used to perform arithmetic/mathematical operations
Consider a = 20 and b = 10

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
2. Relational Operators: used to compare two values
Consider
a = 5
b = 10

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
3. Logical Operators: used to test more than one condition
Consider x = 10 and y = 20

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
4. Bitwise Operators: used to perform bit level operations

PRPEARED BY: PROF. NEHA HARDE ©
BINARY OPERATORS
5. Assignment Operators: used for assigning a value to a variable

PRPEARED BY: PROF. NEHA HARDE ©
TERNARY OPERATOR
The ternary operator is also called as “Conditional Operator”
Syntax:
Condition ? expression1 : expression2
Example:
x = a > b ? a+10 : b;
A ternary operator is a short form of if-else

PRPEARED BY: PROF. NEHA HARDE ©
OPERATOR PRECEDENCE
The precedence of operators determines which operator is
executed first if there is
 more than one operator in an expression
Two ways to solve
= (10+20)*30
=900
=10+(20*30)
=610

PRPEARED BY: PROF. NEHA HARDE ©
OPERATOR PRECEDENCE
Problem:
To generate machine level instructions that could properly evaluate arithmetic expression
Understand the meaning of an expression:
Decide the order in which the operations are to be carried out
Fix the order of evaluation, assign each operator a priority
X = a / b * c - d
X = (a / b * c) - d
X = (a / b)* (c – d)

PRPEARED BY: PROF. NEHA HARDE ©
OPERATOR PRECEDENCE
Understand the meaning of an expression:
Evaluate the expression from right to left or left to right (This order of
evaluation, from left to right or right to left, is called associativity)
A+ B - C
A + (B – C)
(A + B) - C
Operators Precedence and Associativity are two characteristics of operators that
determine the evaluation order of sub-expressions in absence of brackets

PRPEARED BY: PROF. NEHA HARDE ©
OPERATOR PRECEDENCE

PRPEARED BY: PROF. NEHA HARDE ©
OPERATOR ASSOCIATIVITY

PRPEARED BY: PROF. NEHA HARDE ©
PRACTICE QUESTION
What is the output of the code:
#include<stdio.h>
int main()
{
int a = 15;
printf("\n %d %d %d %d", a++, --a, a--, ++a);
// Updated
//Printed
printf("\n %d %d %d", a++, a--, --a);
return 0;
}

PRPEARED BY: PROF. NEHA HARDE ©
INPUT OUTPUT FUNCTIONS

PRPEARED BY: PROF. NEHA HARDE ©
FORMAT SPECIFIERS

PRPEARED BY: PROF. NEHA HARDE ©
FORMATED I/O FUNCTIONS
printf()
Syntax:
printf(“Format string”, List of variables);
Example:
printf(“\n Value of a = %d”, a);
Format string can contain:
Characters to print
Conversion specification (%)
Escape Sequences (\)

PRPEARED BY: PROF. NEHA HARDE ©
FORMATED I/O FUNCTIONS
scanf()
Syntax:
scanf(“Format string”, List of addresses of variables);
Example:
scanf(“%d %f %c”, &a, &b, &c);
Format string can contain:
Conversion specification (%)

PRPEARED BY: PROF. NEHA HARDE ©
UNFORMATED I/O FUNCTIONS
Unformatted Input functions
getch():
getch() is used to get a character from the
console but does not echo to the screen
Library: conio.h
Example:
char ch;
ch = getch();
getche():
getche() is used to get a character from the
console and echo to the screen
Library: conio.h
Example:
char ch;
ch = getche();

PRPEARED BY: PROF. NEHA HARDE ©
UNFORMATED I/O FUNCTIONS
Unformatted Input functions
getchar():
getchar() is used to get or read the input
(i.e a single character) at runtime
Library: stdio.h
Example:
char ch;
ch = getchar();
gets():
gets() accepts single or multiple characters
of string including spaces
Library: stdio.h
Example :
char ch[10];
gets(ch);

PRPEARED BY: PROF. NEHA HARDE ©
UNFORMATED I/O FUNCTIONS
Unformatted Output functions
putch():
putch displays any alphanumeric characters to
the standard output device
Syntax:
putch(variable_name);
Example:
char ch = 'a';
putch(ch);
putchar():
putchar() displays any alphanumeric characters
to the standard output device
Syntax:
putchar(variable_name);
Example:
char ch = 'a';
putchar(ch);

PRPEARED BY: PROF. NEHA HARDE ©
UNFORMATED I/O FUNCTIONS
Unformatted Output functions
puts():
puts() displays single or multiple characters of string including spaces to the
standard output device
Syntax:
puts(variable_name);
Example:
char ch[10]="Example";
puts(ch);