C Language 1st unit material
Programming
in C
Introduction
C is a programming language. It was developed by Dennis Ritchie at
AT&T bell laboratories in the early 1970’s. C was an offspring of the Basic
Combined Programming Language (BCPL) called B language. C language was designed
from B language by adding some modifications to the B language. But C language
compilers were not readily available for commercial use out side of the bell
laboratories. So many programmers preferred C to older languages like FORTRAN
or PL/I of the newer ones like PASCAL and APL.
Why c seems so popular is because it
is reliable, simple, easy to use and easy to learn. First time C language
compilers are available for UNIX operating system. The first C programming text
is written by Brian Kernighan and Dennis Ritchie but this book not provides
complete information about C.
In 1983’s American National
Standards Institute (ANSI) is the organization forms a committee for
development of C language. ANSI C committee releases standardized definition of
C in 1990. International Standard Organization (ISO) is also involved soon for
development of C, because most of the world uses c language.
C is a general purpose, structured
programming language. C combines elements of high level language with
functionalism of assembly level languages (low level languages) so we say C
language is a middle language.
Features of C language:
v Programs written in ‘C’ are efficient and fast. This is due to its
variety of data types and power full operators.
v There are only 32 keywords and its strength lies in its
built-in-functions.
v Several standard functions are available witch can be used for
developing programs.
v C language is well suited for structured programming, thus requiring
the user to think of problem in terms of `functions’ of ` modules’. A proper
collection of these modules of function would make a complete program. This
modular structure makes program debugging, testing and maintenance easier.
v A c program is basically collection of functions that are supported
by the C library. With the availability of a large numbers of functions, the
programming task becomes simple.
v C programs are highly portable. Portable means a C program written
in one environment(O S) can run or executed in another environment with less or
with out modifications.
v C language is also called middle level language. Because it has both
features of high level as well as low level language.
v C is applied in system programming like operating systems,
assemblers, language compilers, text editors and network devices.
v Using c we can solve
scientific, business, mathematical, research applications.
v C language has an important facility called extendibility. It means
you can write your own file and include in other programs.
C fundamentals:
Programming:
Programming is a process to solve a
particular problem by using the computer. When ever we need to computerize a
particular, we have to solve those problems and write these solutions in the
computer understandable code with the help of programming languages.
Program: A program is a group of
instructions which is used to perform particular task. The task’s like big
number out of two numbers, billing process of a hotels or etc…
Instruction: It is command
given to the computer to perform any operation. These instructions may be
addition, subtraction, relation between two numbers etc…
Algorithm: A step by step
procedure use to perform any task is called algorithm. Step by step represent
of a program in general format is called algorithm.
Flow chart: A pictorial
representation of an algorithm is called flow chart. It can also show the flow
of the program. Here we can use several symbols for several works in a program.
These instructions and programs can be
written in different languages like C, C++, java etc… these languages are
called program languages.
Example of an algorithm:
To find a number is an even or odd.
Step1.
Start.
Step2.
Take a number ‘N’.
Step3.
Divide the number by 2 => N/2.
Step4.
If the reminder is ‘0’ then goto Step5 other wise goto Step6.
Step5.
Print the number is even. goto Step7.
Step6.
Print the number is odd.
Step7.
Stop.
High level languages:
Initially (olden days) the computer
programs were written in machine level languages like binary language. Write a
program in binary language and learning binary language is very difficult.
Later assembly languages were developed, with which a programmer can work with
the machine slightly higher level.
Assembly language: It is
one of the programming languages. This is an advanced programming language than
binary language. Write a program in assembly language is nothing; arrange the
instructions in a sequence order to complete the task. In this language we can
write instructions instead of sequence of binary numbers in binary language.
Here instructions are represented in the form of symbolic names like
‘add’,’sub’, etc….
Assembler: An assembler is
used to convert the assembly language program into binary language or specified
machine instructions.
By using assembly languages we can write different programs for
different machines. A program write for one machine can not be run on another
machine, so these languages are called machine dependent languages.
Later these assembly languages are
replaced by high level languages. The first high level language is FORTRAN
(FORmula TRANsulator). One FORTRAN instruction or statement can be executed in
different machines unlike assembly language instruction. Then high level
languages ate called machine independent languages.
Basic structure of a C-program:
Documentation section
Linking section
Definition section
Global value declaration
main()
{
Local variable
declaration part
Executable statements
}
Sub program section
function1()
{
Local variable
declaration part
Executable statements
}
.
.
function2()
{
Local variable
declaration part
Executable statements
}……….
Documentation Section: The documentation
section consists of a set of comments. Here we mention the name of the program
and also write the comments for our program. The comment text can be bounded
with astricks (*) and enclose with in back slash (/). By using these characters
we can write comments for specified statements in our program.
/* The program for
addition of two numbers */
Link Section: The link section provides
instructions to the compiler to link function from the C-language library. In
this section, we can write which header files are use in our program.
#include<stdio.h>
Definition Section: The definition
section defines all symbolic constants. We can use these constants are use many
times in our program. Which value is define in the definition section, we can
not modify or redefine those values any where in the program.
#difine pi 3.14
Global Declaration Section: There are
some variables that are used in more than one function. Such variable are
called global variables and declared in the global declaration section that is
outside of all the function.
I int a,b;
Main function section: Every C program
must have one main() function. This section contains two parts, declaration
part and execution part. The declaration part declares all the
variables used in the executable part. There is at least one statement in the
executable part. These two parts must appear between the opening and the
closing braces. The program execution begins at the opening brace and ends at
the closing brace. All statements in the declaration and executable parts end
with a semicolon.
main()
Subprogram Section: The subprogram
section contains all the user-defined functions that are called by the main
function. User defined function are generally declare, after, end of the main
function.
A Function is a subroutine that may include one or more statements
designed to perform a specific task
Example program for structure of
C-program:
/* Example program
*/ /* Documentation section */
#include<stdio.h> /* Linking section*/
#define a
10 /* Definition
section */
int b; /* Global
variable declaration */
main() /* Main function */
{
int c;
b=10;
c=a+b;
printf(“Sum : %d”,c);
sub(b);
}
void sub(int
y) /* (Sub program or function) */
{
int z; / *
Local variable declaration for function */
z=a-y;
printf(“Subt : %d”,z);
}
Compiling program:
Compiling of c-
program is nothing, to generate binary code file for our program to execute the
program, with the help of compiler.
Compiler: The compiler is a software program, used to convert the program into
machine understandable code (binary code). The compiler analyzes a program, and
then translates it into a form that is suitable to the running computer.
The steps involved to create a program in
C-language are entering program, compiling program and running program. The
program is typed in the computer with the help of editor.
Editor: Editors provide space to write our program in computer. We can also
open the existed programs in the computer. The text editors are usually used to
write C-programs in to file.
Source program: The program that is entered into the file is known as the source
program.
v Open the C-programming language editor.
v Write your program or open an existing program in the system.
v When you create a new program, you have to save the program with a
specific name. We have to follow the naming conventions (rules) to give name
for C-program.
v Give the file name with the extension ‘.C’. This extension
represents a file as a C-Program file.
v After saving the program, compile the program. The compilation
process depends on the editor or running machines operating system.
v For example, if we want to run our program in dos operating system,
we have to follow several steps to compile the program.
o
Go to compile menu in editor.
o
Then chose ‘compile to obj’
command or press ALT+F9 key combination from the key board.
o
The compiler will compile the
program
v The compiler will give the syntax errors in our program. If we have
any errors or warnings we have to rectify the errors, then open our source
program, correct the errors then do the compile process again.
v When ever we have an error free program then the compiler can create
a .OBJ(object) file for machine. It is also called binary code file.
v After creating the .OBJ file then run the program, go to run menu
and choose run command or press CTRL+F9 key combination from the keyboard.
v When ever run a program the linker links the .OBJ file and library
files then create .EXE (executable) file, execute the program by using this
.EXE file.
Linker: It also a software program. By using this compiler links the OBJ
file and library files the produce executable file this process is called
building.
v When ever execute our program, the steps in the program is executed
sequentially this process is called top down approach. If our program get any
data from the user is called input, then process the input and displays result
on the output screen. If the output is correct then completed our task other wise
open the program change the logic according to our requirement.
Integrated development environment
(IDE):
The process of editing, compiling, running and debugging
program is often managed by a single integrated application is known as
Integrated Development Environment (IDE). The IDE’s are differing from form one
operating system to n other. Some windows based IDE’s are Turbo ‘C’, Turbo C++,
Microsoft Visual Basics, Microsoft .NET, etc….
Debugging: In the program does not produce desired results, it is necessary to
go back and reanalyze the programs logic this process is called debugging. By
using this process we can remove bugs (problems) in the program.
Language interpreters:
Interpreters are
another type used for analyzing and executing programs developed in high-level
languages. Interpreters are analyzed and execution of statements in a program
is same time. The method usually allows programs to be more easily debugging.
Basic and java
programming languages are use these interpreters for analyze and execution of
programs.
Character set:
Character set means that the characters and symbols that a C program can
accept. These are grouped to form the commands, expressions, words, C
statements and other tokens for C language character set is the combination of
alphabet or character, digit, special characters and white spaces.
1.
Letters (A…….Z
and a………z) 52
2.
Digits (……9) 10
3.
Special characters (.
, ; : ? / < >….) 29
4.
White spaces Blank,
Horizontal tab, 5
Carriage return, new
line, Form feeds 96
C Tokens:
In a passage of text, individual words and punctuation
marks are called token. Similarly in a C program the smallest individual units
are known as c tokens.
C TOKENS
Keywords Identifiers Constants Strings Operators Special symbols
Float main 50.00 “computer” + - * / {
< [ ? ….
Int a -21.43 “a”
While cost
1.
KEYWORDS:
Every C word is classified as either a keyword or an identifier. All keywords have fixed meaning and these meanings
cannot be changed. Keywords serve as basic building blocks for program
statements. All keywords must be written in lower case.
auto double int struct
break else long switch
case enum register typedef
char exturn return union
const float short unsigned
continue for signed void
default goto sizeof vollatile
do if static while
2. IDENTIFIERS:
Identifiers refer to the names of variables, function
and arrays. These are user-defined names and consist of a sequence of letters
and digits with as a first character. Identifier should not be a keyword.
Variable:
A variable is a data name that may be used to store
a data value. A variable may take different values at different times during
execution. The programmer can choose a variable name in a meaningful way.
Rules for a
variable:
v The first character of the variable name should be a letter
(alphabet).
v A variable should not be a
keyword.
v A variable name can be of any length in recent compilers but some
implementations of C recognize the first eight characters as the valid variable
name.
v No special characters are allowed in the variable name except
underscore.
v The blank space characters are also not allowed while constructing
variable names.
v Upped and lower case letters are different in variable names.
Because C is case sensitive language.
v It is always useful to give the meaningful names to the variables.
Some valid variable
names are.
ROLLNO, Area, arc, n1, n_1, n1_n2……
3. CONSTANTS:
Constants in C refer to fixed values that do not change
during the execution of a program.
1.
Numeric constants:
These have numeric value having combination of sequence
of digits i.e from 0-9 as alone digits or combination of 0-9 ,with or
without decimal
Point having
positive or negative sighn. These are further sub—divided into two categories
as:
a)
Integer Numeric constant
b)
Float Numeric constant
a)
Integer numeric constant:
Integer numeric constant have integer data combination
of 0-9 without any decimal point and with any + or – sign. These are further
sub-divided into three parts.
·
Decimal integer consists of a
set of digits 0-9, preceded by an optional – or + sign.
Examples: q23 -321 +7546
·
Embedded spaces, commas and
no-digit characters are not permitted .
·
An octal integer constant
consists of any combination of digits from 0 to 7, with a leading 0.
·
A sequence of digits proceeding
by OX or ox is considered as hexadecimal integer. They may also include
alphabets ‘A’ through ‘F’ or ‘a’ through ‘f’. The letter ‘A’ through ‘F’
represents the numbers 10 through 15.
Examples: OX2 Ox9F Oxbcd
Note: We rarely
use octal and hexadecimal numbers in programming.
b) Float Numeric constant
Some constants which have a decimal point or a precision
value with in having any positive or negative sign is called floating point
constant . Float constants has two
parts. One is mantissa and the other is exponent pat. These two parts in a real
number are represented as:
Mantissa E exponent
The mantissa is either a real number expressed in
decimal notation or an integer. The exponent is an integer umber with an
optional + or – sign. The letter E separating the mantissa and the exponent can
be written in either lowercase or uppercase.
Example: 3.5x102 can be
written as 3.5E2
2). Character constant:
a) Single character
constant:
It contains a single character enclosed within a pair of single quote marks.
Example: “Hellow” “2007” “X” “9+22+17”
b) String character
constant:
String constant is a sequence of characters enclosed in
double quotes. The characters may be letters, umbers special characters and
blank space.
Example: “hallow” “2007” “x” “9+22+65”
c)
Backslash characters:
C supports some backslash character constants that are
used in output functions. These character combinations are known as escape
sequence.
Constant
|
Meaning
|
‘\a’
|
Audible alert
(bell)
|
‘\b’
|
Back space
|
‘\n’
|
New line
|
‘\t’
|
Horizontal
|
‘\0’
|
Null
|
4. OPERATORS: An operator is a symbol that tells the computer to perform certain
mathematical manipulations.
Types of Operators:
1. Arithmetic 2. Relational 3. Logical 4. Assignment
5. Increment and decrement 6.
Conditional 7. Bitwise 8. Special
Operator
|
Meaning
|
+
|
Addition
|
-
|
Subtraction
|
*
|
Multiplication
|
/
|
Division
|
%
|
Modulo
Division (Remainder after division)
|
1. Arithmetic Operators: Arithmetic
operators are used for arithmetic operations like Addition, Subtraction,
Multiplication, Division etc.
- If all operands are integers, the
result is an integer.
- If an operand is a floating point
or double precision value, the result is a double.
Operator
|
Meaning
|
<
|
Is less than
|
<=
|
Is less than
or equal to
|
>
|
Is greater
than
|
>=
|
Is greater
than or equal to
|
= =
|
Is equal to
|
!=
|
Is not equal
to
|
2. Relational Operators: We often
compare two quantities, and depending on their relation, take certain
decisions. These comparisions can be done with the help of relational
operators. Containing a relation operator is termed as a relational expression
is either 1(true) or (false).
Operator
|
Meaning
|
&&
|
AND
|
||
|
OR
|
!
|
NOT
|
3.LogicalOperators:Anexpression,which combines
two or more relational expression, is termed as a
logical expression.
Logical Table:
A
|
B
|
A AND B
|
A OR B
|
NOT A
|
T
|
T
|
T
|
T
|
F
|
T
|
F
|
F
|
T
|
F
|
F
|
T
|
F
|
T
|
T
|
F
|
F
|
F
|
F
|
T
|
4. Assignment Operator (=): Assignment
operators are used to assign the result of an expression to a variable.
Syntax: variable=expression
Where, expression is whose value is to be assigned to the variable.
Examples: a=10 b=20 sum= a+b
5. Increment and decrement Operators:
The operators ++ adds 1 to the operand and the operator – subtracts 1 from
operand. We use the increment and decrement statements are use in for and while
loops extensively.
Example:
- A prefix operator first adds 1 to
the operand and then the result is assigned to the variable on left.
m=5; Y=++m;
In this case the
value of y and m would be 6.
- A postfix operator first assigns
the value to the variable on the left and the increment the operand.
m=5; Y=m++;
In value of y would
be 5 and m would be 6.
6. Conditional Operator: A ternary
operator pair ‘?:’ is available in C to construct conditional expressions of
the form.
Var1=condition?
exp2: exp3;
The operator ‘?:’ works as fallows condition is evaluated first. If
it is nonzero (true) then the expression exp2 is evaluated and becomes the
value of the var1. If condition is false, exp3 is evaluated and its value
becomes to the value of the var1.
Example: a=10; if(a>b)
b=15; x=a;
X=(a>b)?a:b; else
x=b;
Operator
|
Meaning
|
&
|
Bitwise AND
|
|
|
Bitwise OR
|
^
|
Bitwise
Exclusive OR
|
<<
|
Bitwise Left
|
>>
|
Bitwise
Right
|
~
|
Bitwise NOT
|
7.Bitwise Operators: C has a distinction
of supporting special operators for manipulation of data at bit level.These
operators are used for testing the bits, or shifting them right or left. These
operators are not applicable to the float or double data types.
1. Bit wise AND: The bit
wise AND operator is represented by the symbol &. When this operator
is used, it compare the
corresponding bits in the two operands and when they both are 1 then the
corresponding bit in the result is 1, in all the other cases it is 0.
Example: a=0 0 0 0 0 1 0 1
b=0
1 0 1 0 1 1 1
a&b=0 0 0 0 0 1 0 1
2. Bit wise OR: The bit
wise OR operator is represented by the symbol |. When this operator is
use d, it compare the corresponding bits in the 2 operands and when they both
are 0 then the corresponding bit in the result is 0, in all the other cases it
is 1.
Example: a=0 0 0 0 0 1 0 1
b=0
1 0 1 0 1 1 1
a | b=0 1 0 1 0 1 1 1
3. Bit wise Exclusive OR:
The bit wise OR operator is represented by the symbol ^. When this
operator is used, it compare the corresponding bits in the 2 operands and when
they both are either 0 or 1 then the corresponding bit in the result is 0, in
all the other cases it is 1.
Example: a=0 0 0 0 0 1 0 1
b=0
1 0 1 0 1 1 1
a^b=0 1 0 1 0 0 1 0
4. Bit wise NOT: The bit
wise NOT operator is represented by the symbol ~. When this operator is used, in inverts each bit in the operand. In
other words, each 0 in the operand is changed to 1 and vice-versa.
Example: a=0 0 0 0 0 1 0 1
~a=1 1 1 1 1 0 1 0
5. Right Shift: It has the purpose to transfer the bits of data to the right side.
It is a binary operator that is it has two operands. The left operand is the
data and the right operand is the number of times the shift operation to be
done.
Example: a=
0 0 0 0 0 1 0 1
a>>2= 0 0 0 0 0 0 0 1
Hence, the least
significant bit will be discarded and the most significant bit will come out to
be 0.
6. Left Shift: It has the purpose to
transfer the bits of data to the left side. It is a binary operator i.e. it has
two operands. The left operand is the data and the right operand is the number
of times the shift operation to be done.
Example: a= 0 0 0 0 0 1 0 1 a<<2=0 0 0 1 0 1 0 0
Hence, the most
significant bit will be discarded and the least significant bit will come out
to be 0.
8. Special Operator: These are used for
special purpose in C language. These operations are used in pointers, structures
and unions etc.
1.
Unary operator
2.
Comma operator
3.
Sizeof() Operator
4. Type
operator
5.
Pointer operator
6.
Member selection operator
1. Unary Operator:
These are used for identification of about where it is
signed or unsigned. These are + and -. Also increment or decrement operators
++, -- are in the unary operator category as special operator.
Example: x=-3; y=++x-7*3
2. Comma operator:
The comma operator can be used to link the related
expression together. A comma linked list of expression is evaluated left to
right and the values of right most expression is the value of the combined
expression.
Example: z=(x=10,y=5,x+y);
First assigns the
value 10 to x, then assign 5 to y and finally 15 to z.
3. Size of ()operator:
The sizeof() is a compile time operator and, when used
with an operand, it returns the number of byte the operand occupies. The
operand may be a variable, a constant or a data type qualifier.
Syntax: Variable=sizeof(v or e)
Example: int a;
K=sizeof(a)
the value of k is 2 (because a occupies two bytes of memory)
4. Type operator:
Type operator is used for conversion purpose or casting
purpose. So it is called convert operator. This operator converts float type
data into integer form and vice-versa. It is used for casting a value and
process to convert from 1 form to another is called casting.
Syntax: (Type)v
or e; where v
is variable e is an expression
Example: int a=10, b=3;
float
c;
C=a/b;
If we divide a by
b, then result stored in the c variable be 3.000000. But by using the type
operator, we can get the float value as
C=(float)
a/b;
Now c value is
3.333333
5. Pointer operator:
There are two types of pointer operators used in C
language. These are & and *.
6. Member selection operator:
There operators are used in structure and union. These
are used to create a relation between
owner and member within a structure or union data. These are “.” and à.
DATA TYPES:
C language is rich in its data types. ‘C’ language
supports the following data types.
DATA TYPES
Char array or string enum
Integer structure
Float union typedef
Double
1. Scalar/ standard/ primary/ fundamental data types:
A scalar data type is used for representing a single
value only. It is only called simple or fundamental data type.
Size and range of basic data types:
Data type Size Range of value
char 1 byte -128 to 127
int 2 bytes -32,768 to 32,767
float 4
bytes 3.4e-38 to 3.4+38
double 8 bytes 1.7e-308 to 1.7e+308
2. Derived data types:
Derived data
types are derived from the scalar data type by adding some additional
relationship with the various elements of the primary or scalar data types.
Note that derived data type may be used for representing a single value or
multiple values. These are further sub divided into three categories.
1. Array and
strings 2. Structures 3. Unions
(a). Arrays: An Array is nothing but a collection of sequence of
homogeneous(similar) data type elements.
Declaration of an array:
Data type
variable-name [size];
Where datatype can be any primary or secondary datatypes. Size is
any integer.
Example: int a[50];
(b). Structure: A Structure is nothing but a collection of heterogeneous
(different) datatypes of elements.
Declaration of structure:
Struct tage_name
{
datatype field1;
datatype field2;
………………
datatype field n;
};
Where tagename is the name of the structure / datatype can be any
primary or secondary datatype.
Example: struct student
{
int sno;
char name[10];
float m1,m2,m3;
};
Once the structure
data type is defined, the variable of that
datatype can be declared of follows.
Syntax: struct
tagname variablelist;
Example: struct student s;
3. User defined type:
This is also used for definition, i.e. it allows the
users to define a variable or an identifier, which is used for representation
of existing data types.
a) enum: Another user defined data type is enumerated data type provided by
ANSI standard.
Syntax: enum identified {value1, value2…..}
variable;
The
identifier is a user- defined enumerated data type, which can be used to
declare variables that can have one of the values enclosed within the braces
known as enumeration constant.
Example: enum
day{Monday, Tuesday, Wednesday,..} d;
b). type def: Supports a feature know “type definition” that allows user to
define an identifier that would represent an exiting data type. The
user-defined data type identifier can later to declare variable.
Syntax: typedef data_type identifier;
Where type
represents the data type of the identifier refers to the ‘new’ name giving to
the date type.
Ex: typdef
int marks;
Here marks
symbolize int. they can be later used to declare variable as follows.
marks
m1,m2;
m1,m2 are declared
as int variable. The main advantage of typedef is that we can create meaningful
data type names for increasing the readability of the program.
4. Void:
Void or empty data type is used in user defined function
or user defined sub programs. These are used when the function sub-program
returns nothing to the calling location. Also it is used when a function or a
sub-program have not any argument in it.
5. Pointer data type:
Pointer data type is
used to handle the data at their memory address.
Input / output functions
In ‘C’ language I/O
functions are categorized into following two types.
1.
Formatted I/O
statements:
All input/output operations are carried out through function calls
such as printf and scanf there exist several functions that have more or less
become standard for input and output operations in C. There functions are
collection known as the standard i/o library.
#include<stdio.h>
The instruction <stdio.h>
tells the compiler to search for a file stdio.h and place it’s contents at this
point in the program. The content of the header file become part of the source
code when it is compiled.
Conversion character
|
Meaning
|
%d
|
Integer
|
%f
|
Float
|
%c
|
Character
|
%s
|
String
|
%lf
|
Double
|
a). scanf():
The scanf() function is an input
function. It used to read the mixed type of data from the keyboard. You can
read integer, float and character data by using its control codes or format
codes.
Syntax: scanf(“control string”,&v1,&v2…);
The control string contains the
format of data being received. The ampersand symbol ‘&’ before each
variable name is an operator that specifies the address of variable v1.
Example: scanf(“%d”,&n);
The control string %d specifies that
an integer value is to be read from the terminal (keyboard).
b). printf():
printf() fi\unction for printing
captions and numerical results the general form of printf statement is….
printf(“controle
string”,arg1,arg2…);
control
string consists of three types of items:
Ø Characters that will be printed on the screen as they appear.
Ø Format specifications that define the output format for display of
each item.
Ø Escape sequence character such as \n,\t….. the control string
indicates how many arguments follow and what their types are the argument
arg1,arg2… are the variable whose values are formatted and printed according to
the specification of control string.
2.
Unformatted I/O statements:
These functions are used to read or print the data in unformatted
way. These are also called as character I/O functions. The following are the
character I/O functions.
Input functions output functions
getchar(); putchar();
getche(); putc()
getch();
gets();
a). getchar():
This is an input function. It is
used for reading a single character from the keyboard. It is buffered function.
Bu8ffered functions get the input from the keyboard and store it in the memory
temporarily until you press the enter key. After you pressed the enter key then
input move to a relevant variable.
Syntax: v=getchar();
Example: char a; a=getchar();
b). gets():
This is an input function. It is
used for read a string from the keyboard. It is a buffered function it will
read a string, when you type the string from the keyboard and press the enter
key from the keyboard. It will mark null character (‘\0’) in the memory at the
end of the string, when you press the enter key.
Syntax: gets(v);
Example: char s[20]; gets(s);
c) getch():
This is also an input function. This
is used to read a single character from the keyboard like getchar() function.
But getchar() function is a buffered function; getch() function is a non
buffered function. When type the character data from the keyboard it does not
visible on the screen.
Syntax: v=getch();
d). getche():
All are same as getch() function
except that when you type the character data from the keyboard it will be
visible on the screen.
Syntax: v=getche();
e). putchar():
This function is an output function.
It is used to display a single character on the screen.
Syntax: putchar(v);
Example: char a; getchar(a);
f). puts():
This function is an output function
. It is used to display a string inputted by gets() function, which you will
read in the next on the screen.
Syntax: puts(v); or
puts(“text);
Example: char a[10]; gets(a);
Comments
Post a Comment