CSC3C03-Problem Solving Using C

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 98

1

CSC3C03-PROBLEM SOLVING USING C


MODULE-1

 PROGRAMMING LANGUAGES
A computer language is used to make a computer understand what the user
wants to say. When a user writes a program, programmer uses programming
language.

A program, written in a programming language, is a set of instructions by


which the computer comes to know what is to be done. It is a coding language
used by a programmer to write the instructions that a computer can understand.

Programming Languages

High-Level Languages

It uses English-like languages. High –Level languages are converted into


machine level language using a converting software (Translator) called COMPILER
2

or INTERPRETER. It is a computer programming language that does not requires


great efforts from the programmer. It is close to the users.

Eg: FORTRAN, COBOL, C , C++,PYTHON,JAVA etc…

Machine Language

Machine language consisting of 0s and 1s.The computer understands only 0’s


and 1’s . It is a low level language and is more machine friendly.

TRANSLATORS

A translator is a computer program that can instantly translate between any


languages. It converts program language to machine language. There are 3 types of
translators.

o COMPILER
o INTERPRETER
o ASSEMBLER

Compiler

It converts high-level language to machine language (0s&1s). The compiler


checks for syntax errors in a source code of a program. If no error is found, the
compiler translates the code into binary format. The compiler reads the whole
programs and then translates it into machine language.

Interpreter

Interpreter translates high-level language to low-level machine language. An


interpreter read the statement and converts it into an intermediate code and executes
it, before reading the next statement. It translates each instruction one by one.

 HISTORY OF C
C is a High-level , structured, machine independent programming language.
In 1972 , the “Traditional C” language was developed by Dennis Ritche. It allows
software developers to develop programs without worrying about the machine type
instruction. It allows so many facilities to programmers. By the use of C language, the
calculation process became easy.
3

 IMPORTANCE OF C

1. Robust Language
2. Efficient and Fast
3. Built-in Functions
4. Portable
5. Structured Programming
6. Extend itself

Robust Language

C is a strong high-level programming language. So it is known as robust


languages. Its rich set of built-in functions and operators can be used to write any
complex program. C compiler translates the High level language to Low-level
language (Machine language).

Efficient and Fast

Programs written in C are fast and efficient. This is due to verity of data type
and powerful operators. It is many faster than other programming languages like
BASIC, COBOL etc.

Built-in Functions

Several standard functions are available in C library. C contains 32 strong


keywords and its strength lies in its built-in function.

Portable

This means that programs written for one computer can be run on another
without any modification.

Structured Programming

The entire program can be divided into function blocks or modules. A proper
collection of these modules would make a complete program. This modular structure
makes program debugging, testing and maintenance easier.

Debugging: The process of identifying and removing errors (mistakes) from program

Testing: The process of executing a program with the intent of finding errors.
4

Maintenance: The process of modifying a program after completing the given


program

Extend Itself

A C program is basically a collection of functions that are supported by C library. We


can continuously add our own functions to C library. So the programming task much
easier.

C LIBRARY

It is just like a standard library. But here hold functions rather than books. So many
built-in functions are available in C library. We can include desired functions to our C
program by calling the specified function with its header file.

 STRUCTURE OF C PROGRAM
Documentation Section
Link Section
Definition Section
Global Declaration Section
main() Function Section
{
Declaration Part
Executable Part
}
Subprogram Section
Function1
Function2
Function3 (User Defined Functions)
…………..
……………
Function n

1) Documentation Section
5

It consist of comment lines giving the name of program, author name,


other details and also can include points in middle of program.

We can give 2 types of comment lines =>

a) // : For describing single line comment


b) /*…………
…………..*/ : For describing multiline comment
 Eg:
Single line
//Sree Narayana College
Multline
/* this is a
C program*/

2) Link Section

It provides instruction to the compiler to link functions from the system


library.

Eg: #include<stdio.h>

3) Definition Section
It defines all symbolic constants.
Eg: pi=3.14
4) Global Declaration Section

There are some variables that are used in more than one function. Such
variables are called global variables and that are declared in global
declaration section.

5) main ( ) Function Section

Every C program must have one main( ) function section. The program’s
execution is starting from this main ( ) function.

It contains 2 parts.
a) Declaration Part
6

It declares all the variables that are used in the program.


b) Executable Part

The main execution takes place at this part. The program


execution starts at the opening brace( { ) and ends at the closing
brace( } ).

All statements in C program ends with semicolon ( ;).

6) Sub program Section


It contains all user defined functions that are called in the main function and
somewhere else. User defined functions are generally placed immediately after
the main ( ) function.

 CHARACTER SET
The task of processing of data is accomplished by executing a sequence of
instructions is called a PROGRAM. These instructions are formed using certain
symbols and words according to some rules known as SYNTAX
RULES(Grammar).

The character set that can be used to form words, numbers and expressions
depends upon the program. The character set in C can be classified to the
following categories.

1. Letters
2. Digits
3. Special Characters
4. White Spaces

Letters

C language supports all the alphabets from the English language. Lower and
upper case letters together support 52 alphabets.
lowercase letters - a to z UPPER CASE LETTERS - A to Z
Digits

C language supports 10 digits which are used to construct numerical values in


C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
7

Special Characters

C language supports a rich set of special symbols that include symbols to


perform mathematical operations, to check conditions and so on..
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : …….
White Space

Horizontal Tab, newline space, blank space …. are considered to white spaces

 C TOKENS
Normally, individual words and punctuation marks are called tokens. In a C
program the smallest individual units are known as C TOKENS. C has six types of
tokens. They are given below.

Keywords

All keywords in C programming have fixed meanings and these meaning


cannot be changed. Keywords serve as basic building blocks for program statements.
All keywords must be written in lowercase.
8

Eg : int , float, for, case, do, return…………

Identifier

Identifiers are used for naming purposes. It refers to the names of variable,
functions and arrays. It consists of letters, digits and underscore ( _ ). Both uppercase
and lowercase are permitted, both are distinct.

Rules for Identifiers

a. First character must be a letter or underscore( _ )


b. Must consists of letters, digits and underscore ( _ ) only
c. Cannot use special symbols other than underscore( _ )
d. Cannot use keywords
e. Must not contain white space.
2) Eg: Valid & Invalid Identifiers

STRINGS

❏ Sequence of Characters in a C program is Known as Strings.

SPECIAL CHARACTERS

❏ Special characters or punctuators in c are used to separate individual parts in a


program.

Eg: ; is used to indicate end of a statement(line).

❏ Some of these can have various meanings in various contexts.

OPERATORS
9

Operators are symbols that are used to represent a mathematical calculation or logical
comparison.

5+9

X+Y

m>n

 DATA TYPES
As its name indicates, a data type represents type of the data which you can
process using your computer program. Data types specify how we enter data into our
programs and what type of data we enter. The type of a data item determines how
much space it occupies in storage and what operations should be performed on that
item. “Data type defines character and required memory space of a data item.”

Eg: STUDENT NAME : Akshay : String

MARK 1 : 86 : Number(Integer)

MARK 2 : 76.5 : Number (Fractional)

The C programming language supports almost every type of data. They are given
below.

1) Primary Data Types(Fundamental)


2) Derived Data Types
3) User-Defined Data Types

Fundamental Data Types

A fundamental data type is a data type where the values that it can represent have a
very simple nature (a number, a character). C support mainly 5 Fundamental data
types, and they are given below.

❏ Integer Type
❏ Floating Type
❏ Double Type
❏ Character Type
❏ Void Type
10

❏ Integer Type
Integers are whole numbers with a range of values supported by a particular
machine. The integer data type holds these types of values including positive
negative and zero type numbers.

The integer type representation in computer system:

int

❏ Floating type
Floating point numbers are real numbers with a range of values. It includes
fractional numbers (point values) also. The floating data type holds these types of
values including positive negative and zero type numbers.

The floating type representation in computer system:

float

❏ Double Type
Floating point data type hold only 4bytes of data. If a data comes with more
than that range, an error may arise. To avoid that problem C support another data
types called double type that is much larger range than others.

Representation:

double

❏ Character Type
When we want to store a character value in our program, the above mentioned
data types are not significant. For that purpose C support a character oriented data
type.

Representation :
11

char

❏ Void type
The void type has no value. It returns a null value. In a C program, void type
mostly used in module wise programs. It represents each module’s character.

Representation

void
 VARIABLES
A variable is an identifier that denotes a storage location used to store data value.
A variable may take different values at different times during the execution of the
program. All the rules of identifiers must follow when choosing a variable name.

Eg:
Name
mark1
clg_name

 VARIABLE DECLARATION
After designing suitable variable names, must declare them to compiler.
Declaration does two things:

1. It tells the compiler what the variable name is.


2. It specifies what type of data the variable will hold.

The declaration of variable must be done before they are used in the program.

Syntax:
12

Eg:

int a,b,c;

char gender;

float average_score;

int mark1;

DISPLAY IN C
C supports an output display function called printf(). This function is used to
display a message or value in a given program. It is a built-in function in C library.

Syntax:

printf(“message”);

Eg:

 Display state name


 printf(“Kerala”); //output:Kerala
 Display a fruit name
 printf(“MANGO”); //output:MANGO
13

 Display a number
 printf(“100”); //output:100

 OPERATORS
Operators are symbols that are used to represent a mathematical calculation,
logical comparison etc. Based on the functionality, C operators are categories into the
following eight types.

 Arithmetic Operators

 Relational Operators

 Logical operators

 Assignment Operators

 Increment Decrement Operators

 Conditional Operators

 Bitwise Operators

 Special Operators

Arithmetic Operator

The operators are used to perform basic mathematical operations such as


addition, subtraction, multiplication division etc.

They are :

Addition : To add two operands

Symbol : +

Eg : 52+8

Subtraction : To subtract two operands

Symbol : -
14

Eg : 12-2

Multiplication : To multiply two operands

Symbol : *

Eg : 6*3

Division : To divide left hand operator by right hand operator

Symbol : /

Eg : 10/2

Modulus : To find remainder

Symbol : %

Eg : 5%2 #result=1

Relational Operator

These operators are used to compare values. It is also called Comparison


Operators. The result of these operators is always true or false (Boolean).

1. == Equal To
To check whether tow operators are equal
10==20 return false
2. != Not Equal To
To check whether two operators are not equal
10!=40 return true
3. > Greater than
To check whether first operand is greater than second operand.
20>87 return false
4. < Less than
To check whether first operand is less than second operand
23<10 return true
5. >= Greater than or equal to
To check whether first operand is greater than or equal to second
operand.
15

10>=20 return false

6. <= Less than or equal to


To check whether first operand is less than or equal to second operand
30<=67 return true

Assignment Operator

This operator used to store right side operand/value in the left side operand.

Syntax:
variablename=value;
variablename=expression
A=10

Bitwise Operator

These operators perform bit level operation on operands.

Eg: x=10 y=12

Corresponding binary value:

x=1010 y= 1100

1. & - Bitwise AND


Performs AND operation between operands
x&y => 1000
2. | - Bitwise OR
Performs OR operation between operands
x|y => 1110
3. ^ - Bitwise XOR

Performs XOR operation between operands

x^y => 0110

4. << - left shift


Used to shift the bits towards left
x<<2 => 101000
5. >> - right shift

Used to shift the bits towards right


16

x>>2 => 0010

Logical Operators

These operators are used to check two or more conditions. The resultant is
always a Boolean value.

1) && - Logical AND


Performs logical AND operation
2) || - Logical OR
Performs logical OR operation
3) ! - Logical NOT
Performs logical NOT operation. That is, to reverse the operand state.

Conditional Operators

This operator is used to construct a conditional expression of the form:

exp1?exp2:exp3;

Evaluates exp1

If the exp1 is true , then exp2 is evaluated and return

If the exp1 is false, then exp3 is evaluated and return. Here exp2 never be
considered.

 Eg:

result=mark>=40?”pass”:”fail”;

Here if the mark is 87, then it returns pass to result variable, otherwise returns fail to
result variable .

Increment Operators

The increment operator ++ adds 1 to the operand. It can be of two forms.

Syntax

++operand;

operand++;
17

Eg:

a++;

++a;

Both are same in execution time.

Two Types:

 Pre Increment

++operand

Principle :change and use

add 1 to operand and use it.

 Post Increment

operand++

Principle: use and change

use it and add 1 to operand

Decrement Operator

The decrement operator - - subtract 1 from the operands.

Syntax:

--operand;

operand--;

Eg:

a--;

--a;

Both are same in execution time.

Two Types:
18

 Pre Decrement

--operand

Principle :change and use

subtract 1 from operand and use it.

 Post Decrement

operand--

Principle : use and change

use it and subtract 1 from operand

Example

Output
19

Special Operators

1) Comma operator
2) sizeof() operator

Comma Operator

The comma operator mainly used to separate variables in a program. And also
used in iteration statements.

Eg:

Declare 3 variables as Integer type.

Without comma operator:

int a;

int b;

int c;

With Comma operator:

int a,b,c;
20

sizeof() operator

This operator is used to find the desired size of a given variable.

Syntax:

sizeof(variablename);

Eg:

int a=10;

sizeof(a);

 STATEMENT
A statement can be thought as an instruction that can be compiled by the C compiler.
A statement is compiled by the compiler and after execution displays some results (if
it needs).

C supports so many statements like, if –else, while, for, printing etc.

Eg:

1. mark=98;

2. printf(“KERALA”);

 EXPRESSIONS
An expression is a combination of variables, constants and operators. C can
handle any complex mathematical expressions.

Eg:

a+b*c

x-y+20
21

(a+b)/2

a*a

2*a/b

 PRECEDENCE OF OPERATORS
When an expression has two or more operators, the system needs to
identify the correct sequence to evaluate these operators. Sometimes the result may
wrong. To avoid this problem, a level of precedence is associated with the operators.
Precedence is the condition that specifies the importance of each operator relative
to others.

High to Low Precedence in C

1) ( ),[ ]

2) * , / , %

3) + , -

The other relational , logical operators have less precedence

<,<=,>,>=………..

 ASSOCIATIVITY
We can see that many operators are having same precedence. In that case, we
use Associativity to evaluate the expression. Associativity is nothing but the
direction in which we evaluate the operators if they have same precedence.

There are two types of associativity.

1) Left to Right

The operator of same precedence is executed from left side first.

2) Right to Left
The operator of same precedence is executed from right side first.

Eg:

Expression:
22

2+5-3

L 2 R:

add 2+5 =7

then 7-3=4

R 2 L:

Subtract 5-3=2

then 2+2=4 //Result same

OPERATOR CLASSIFICATION

Based on the number of operands, operators can be classified into two.

1. Unary Operator
Unary operators are operators with only one operand.
++ --
Eg:
x=30
--x
29 //output

2. Binary Operator
Binary operators are operators with two operands. They are used to basic
calculations and comparisons.(Arithmetic, Relational, etc)

+ - * / < %

Eg: a=10

b=90

a+b

100 //output

3. Ternary Operator

Ternary operators are operators with three operands. They are used to
basic condition checking.(Conditional Operator)
?:
23

Eg: result=mark>=40?’P’:’F’;

 MATHEMATICAL FUNCTIONS
C supports some built-in functions to find the square root, power, sine value
cosine value etc. To add the functionalities of this function in program include the
appropriate Header file from C Library.

Header File for Mathematical Function: math.h

Including this to program,

#include<math.h>

Basic Functions:

 sqrt(n): to find squre root of a number or variable

 pow(x,y): to find the power of a variable or number

pow(2,3): 2 to the power 3= 8

 sin(x) : sine value of x

 cos(x): cosine value of x

Basic Arithmetic Programs

1. C program to perform basic arithmetic calculations include addition,


subtraction, multiplication and modulo.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,result,root;
clrscr();
printf("Enter The numbers\n");
24

scanf("%d%d",&a,&b);
result=a+b;
printf("Sum=%d\n":result);
result=a-b;
printf("Difference=%d\n":result);
result=a*b;
printf("Product=%d\n":result);
result=a%b;
printf("Reminder=%d\n":result);
root=sqrt(a);
printf("Square Root=d\n":root);
getch();
}
2. C program to perform division.
#include<stdio.h>
#include<conio.h>
void main()
{

float a,b,result;
clrscr();
printf("Enter The numbers\n");
scanf("%f%f",&a,&b);
result=a/b;
printf("Sum=%f\n":result);
getch();
}

 INPUT/OUTPUT (I/O) FUNCTIONS IN C


Reading/writing data at runtime
C has certain input/output (I/O) functions that can be used for reading and
printing data of all types. Such functions depend on control string/format
specifier to identify the type of data that is read/displayed.

scanf( ) - The scanf( ) function is used to read formatted input data.


Syntax:- scanf(“format specifier”,&variable name);
25

printf( ) - The printf( ) function is used to display formatted output


data.
Syntax:- printf(“format specifier”,variable name);

Data type Format specifier


char %c
int %d
float %f
string %s
Eg:- int num;

printf(“Enter a number: ”);

scanf(“%d”,&num);

printf(“The number entered is: ”);

printf(“%d”,num);

Output:- Enter a number: 654

The number entered is: 654

Reading/printing Single Character

getchar() - The getchar( ) function reads single character at a time.

Syntax:- variable name=getchar();

Example:- char answer;

printf(“Enter Y for Yes and N for No: ”);

answer=getchar();
26

putchar() - The putchar( ) function prints single character at a time.

Syntax:- putchar(variable name);

Example:- printf(“The response is: ”);

putchar(answer);

Output:- Enter Y for Yes and N for No: Y The

response is: Y

Reading/printing Group of Characters(string)


gets() - The gets( ) function reads group of characters(string) .

Syntax:- gets(string variable name);

puts() - The puts( ) function displays a string .

Syntax:- puts(string variable name);

All the input-output functions discussed


above are defined in the header file stdio.h.
27

Module-2
 DECISION MAKING STATEMENTS
When a program breaks the sequential flow and jumps to another part of the
code is called branching. When the branching is based on a particular condition it is
called conditional branching statements. It is also called Selection statements.

Java language supports such type of statements and they are :

1) If statement
2) Switch statement
3) Conditional operator statement

If statement

It is used to control the flow of execution of statements. It allows the computer


to evaluate the expression or condition first and then, depending on whether the value
of the condition is ‘true’ or ‘false’, it transfers the control to a particular statement.

An if statement may be implemented in different forms.

a) Simple if statement
b) if –else statement
c) else if ladder
d) Nested if –else statement

Simple if statement
28

Syntax:

if (condition1)

statement 1;

statement n;

If condition1 is TRUE, execute statement1 and go to statement n. Otherwise


execute statement n only.

Eg:

if(3<4)

printf (“Four”);

printf (“Haii”);

Output

Four

Haii
29

if –else statement

Flowchart

Syntax:

if (condition1)

statement 1;

else

statement 2;

statement n;
30

If condition1 is TRUE, execute statement1 and then go to statement n. If


condition1 is FALSE, execute statement2 and then go to statement n.

if(3>4)

printf((“Four”);

else

printf(“Three”);

printf(“Haii”);

Output

Three

Haii
31

else-if ladder Statement

Sytax:

if (condition1)

statement 1;

else if(condition2)

statement2;

else if(condition3)

statement3;

else

statement ;

statement n;

 If the condition1 is true statement1 executed and go to statement n.

 If the condition1 is false go to next line and check the condition2, if it true
execute the statement2 and go to statement n.

 If it again false, go to next line and check condition3 and so on.

 If the every condition is false the last statement in the else block is executed.
32

Eg:

if(3>4)

printf (“four”);

else if(7>99)

printf (“haii”);

else if(33<44)

printf (“haii”);

else

printf (“all the conditions are false”);

}
33

Nested if –else statement

An if statement contains another if statement is called nested if.

Syntax:

if (condition1)

if (condition2)

statement2;

else

statement3;

else

statement 4;

statement n;

If condition1 is TRUE, execute statement1 and then go to if statement block. Here


another if statement is present. So check that condition and so on. If condition1 is
FALSE, execute statement4 and then go to statement n.
34

Eg:

if(3<4)

if(4<5)

printf (“4”);

else

printf (“5”);

else

printf (“Three”);

printf (“last statement”);

 SWITCH STATEMENT
When using the else if ladder statement, the program become difficult to
read and follow. Java supports a multi way decision statement known as switch. The
switch statement tests the value of a given variable against a list of case values and
when a match is found, a block of statements associated with the case is executed.
35

Syntax:

switch (expression)

case value1 : statement1; break;

case value2: statement2;break;

case value3 : statement3;break;

………………………………………….

………………………………………….

default : statement n;

Working

When switch is executed, the value of expression is successively compared


against the values value1,value2 … If a case is found whose value matches with the
value of the expression, then block of code that follows the case are executed.

The break statement at the end of each block indicates the end of the particular
case statement. And control transferring out of switch statement.

If none of the case values does not match, the default statement will execute.
It is optional.

Eg:

switch(3)

case 1 : printf(“One”);break;

case 2 : printf(“Two”);break;

case 3: printf (“Three”);break;


36

case 4: printf (“Four”);break;

default : printf (“invalid number”);

Output

Three

 ITERATION STATEMENTS (LOOPING STATEMENTS)


The process of repeatedly executing a block of statement is known as iteration
statement or looping statement. The statements in the loop executed any number of
times.

It can classified into two:

1) Entry –Controlled Loop


2) Exit- Controlled Loop

Entry Controlled Loop

The control condition tested before the start of loop statements. If the
condition is false, then loop statements never executed.

Types : for loop & while loop

Exit Controlled Loop

The control tested after the looping statement. The Loop statement executes
unconditionally at the first time. After finishing first iteration, if the condition is false,
then loop statements never executed.

Types : do-while loop

Looping Structure

Every looping statements must contains the following parts

Initialization statement: setting a loop starting value.

Condition Statement: testing occurs


37

Execution Statement: loop body, based on given condition

Increment or Decrement Statement: iteration takes place

for Loop
Syntax:

for(initialization;condition;increment/decrement)

body of the loop

Working

 1. initialization made with in the for statement.

 2. test the given condition

 3. condition true: executes the body of the loop

a)after executing the looping body, go to

b)increment/decrement section.

c)Update the value.

d)Again test the condition and so on.

 4.Condition false: never executes the loop body. Control passed to out of the
for loop

Eg:

Display natural numbers 1-7

for(int i=1;i<=7;++i)

printf(“%d\n”,i);

}
38

Output

while Loop
Syntax:

Initialization;

while(condition)

Body of the loop;

increment/decrement;

}
39

Working

 1.initialization made before while statement.

 2.test the given condition

 3.condition true: execute the loop body. The increment/decrement present in


that section.

After update increment/decrement, test condition again and so on.

 4.condition false: never executes the loop body. Control passed to out of the
while loop.

Eg:

i=100;

while(i>=97)

printf(“%d\n”,i);

i--;

Output:

100

99

98

97
40

do-while Loop
Syntax:

Initialization;

do

Body of the loop;

increment/decrement;

while(condition);

Working

 1.initialization made before do-while statement.

 2.once executes the loop body.

Increment/decrement present in the section

 3.After updating the value , test the condition.

 4.Condition true: repeat loop body and so on.

 5.Condition false : never executes the loop body. Control passed to out of the
while loop

Here, loop body executes at least once unconditionally


41

Eg:

a=30;

do

printf(“%d,”,a);

++a;

while(a<35);

Output

30,31,32,33,34

 NESTING OF FOR LOOPS


A for loop contains another for loop is called nesting of for loop. This is used
for two or more dimensions. Here, Outer loop and inner loops are present.

Syntax:

for(initialization1;condition1;increment1/decrement1)

//Body of outer loop

for(initialization2;condition2;increment2/decrement2)

Body of inner loop

}
42

Working

 1. initialization1 made with in the outer for loop statement.

 2. test the given condition1

 3. condition1 true: executes the body of the loop

here, another loop present. So again

 a. initialization2 made with in the inner for loop statement.

 b. test the given condition2

 c. condition2 true: executes the body of the loop

a)after executing the inner looping body, go to

b)increment2/decrement2 section.

c)Update the value.

d)Again test the condition2 and so on.

 d.Condition2 false: stops the execution of inner loop body. Control passed to
outer for loop’s increment/decrement section

 Update the value and test condition1 and if it is true go to inner loop and so on

 4.condition true false: never executes the loop body. so inner loop also stop its
execution. Control passed to out of the for loop

Eg:

for(i=1;i<=3;++i)

for(j=3;j>=1;--j)

printf("i=%d j=%d\n",i,j);

}
43

Output

 JUMPS IN LOOP
Loop performs a set of operations repeatedly until the condition fails.
Sometimes, when executing a loop it becomes desirable to skip the loop or a part of
the loop. The jumping statements are used for this purpose. They are:

1) Jumping out of a Loop

An early exit from a loop can be accomplished by using the break


statement. When the break statement is encountered inside a loop, the loop is
immediately exited and the program continues with the statement immediately
following the loop.

When the loops are nested, the break would only exit from the loop
containing it. That is it will exit only a single loop.

Syntax:
break;
44

2) Jumping to specified location : goto statement

The goto can transfer the control to any place in a program. Another use of
goto statement is to exit from entire loop if it nested. The break statement would
not work like this.

Syntax: goto Label;

………………..

Label :

3) Skipping a Part Of a Loop

This statement causes the loop to be continued with the next iteration after
skipping any statement in between. Skip the following statements and continue
with the next iteration. Java support a statement called continue for this purpose.

Syntax:

continue;
45

Example

for(i=1;i<=5;++i)

if(i==3)

continue;

printf(“%d\n”,i);

Output

5
46

Module-3

 ARRAYS
An array is a group of contiguous or related data items that share a common
name. An array can be used to represent a list of numbers, names etc. It uses one
variable name and multiple data. So each data represented by its location. Array
location indicated as index or subscript. The values in an array named as elements.

Based on the number of indices, it can be categories into different parts.

 One Dimensional Array


 Two Dimensional Array
 Multi Dimensional Array

One Dimensional Array

A list of items can be given one variable name using only one subscript/index
and such a variable is called one dimensional array. The Symbol [] is used for array
representation. The array index starts at 0th location.

 Array representation : arrayname[ ]

Here,

arr[0]=10
47

arr[1]=20

arr[2]=30

arr[3]=40

arr[4]=50

‘arr’ means the array name and the 0,1,2 etc are the indices of the array ‘arr’.

The 10, 20 ,30 etc are the data hold in the array named ‘arr’

 CREATING ONE DIMENSIONAL ARRAY


 Declaration
 Assigning Values
Like other variables, array must be declared before used.

Declaration Syntax:

datatype arrayname[size];

Eg:

int a[100];

float avg[50];

char name[100];

Assign values to arrays

Assign values to an array means insert data into the corresponding array. Like
variables, we can assign values to an array in two ways.

 Compile Time Initialization

 Run Time Initialization


48

Compile Time Initialization

Insert values to the array at the time of program creation is called compile time
initialization.

Syntax:

1)

arrayname[index]=value;

2)

datatype arrayname[size]={value1,valu2,value3………};

Eg:

A[0]=12;

int mark[10]={67,98,78};

Run Time Initialization

Insert data into the array at program execution time. scanf() function is used for run
time reading. By using scanf() and looping statements we can insert elements to an
array at run time.

int a[10];

for(i=0;i<10;++i)

scanf(“%d”,&a[i]);

}
49

Here,

a= array name

i= a variable for index that increasing the value

 Array Limit
At the time of declaration of an array the size should be mentioned. If the
programmer cannot used much size he can set the wanted size at runtime. To
set that, an variable is used and store particular size the programmer want.

int a[20];
printf(“Enter the Limit of array\n”);
scanf(“%d”, &n);
for(i=0;i<n;++i)
scanf(“%d”,&a[i]);

here, n is the limiting variable. The size is 20, but the array variable a can store
only the specified number n.
 ARRAY OPERATIONS
 Traversal

 Searching

 Sorting

Traversal

Traversal means that visiting each location of the array. That is just displaying
all elements is known as traversing. For this printf() function can used.
50

Example

Searching

Searching means to check the specified data value is present in the given array. If it
present just display the location.

Process

 item present before last location : but, loop never stops its execution until the
condition false.

 So if the item found, stops the loop, by using break statement.

 if the item found , then Set a variable , and break the loop.

 After the loop statement, check the already used variable. And display the
result

Example
51

Sorting

Arrange the set of data in ascending or descending order is known as sorting.

Basically the sorting takes place with a temporary variable.

Example

 TWO DIMENSIONAL ARRAY


A list of items can be given one variable name using only one subscript/index
and such a variable is called one dimensional array. The Symbol [] is used for array
representation. The array index starts at 0th location.

 2D Array representation : arrayname[ ][ ]


52

Declaration

datatype arrayname[row_size][column_size];

Eg:
int a[10][10];
float matrix[20][30];

Initialization

1. Compile Time Initialization


2. Run Time Initialization

 Compile Time

1)

arrayname[row][column]=value;

Eg: arr[0][0]=10;

arr[1][2]=22;

2)

datatype arrayname[rowsize][columnsize]={{R1values},{R2values}….};

Eg: int a[10][10]={{0,0,0),{1,1,1}};


53

000

111

 Run Time

int a[10][10];

for(i=0;i<10;++i)

for(j=0;j<10;++j)

scanf(“%d”,&a[i][j]);

} }

 STRINGS
A string is a sequence of characters that is treated as a single data item. It
represent in double quotes.

Eg: “hai”

In C programming there is no data type to support strings. To solve this problem


use the character array concept. An array is a collection of elements and if it is a
character type, then it is termed as strings or character array.

The compiler automatically supplies a ‘\0’ character to the end of every string.

Declaration

Syntax:
54

char string_name[size];
Eg:
char name[25];

char college[50];

Initialization

 Compile time

char variablename[size]=“string”;

Eg:

char name[10]=“RAJU”;

Representation:

R A J U \0 \0 \0 \0 \0 \0

Example
55

Run Time

scanf() function is used to read run time initialization. Here the control string is
%s

Syntax:

scanf(“%s”,variable);

eg:

char name[20];

scanf(“%s”,name);

Example

 READING A LINE OF TEXT


When using scanf() function, there is a problem behind it. A scanf() function can read
only a single word. It cannot read a sentence. To achieve this feature C supports
another function called gets().
56

Syntax:

char variablename[size];

gets(variable);

Eg:

char fullname[50];

gets(fullname);

 WRITING A STRING VALUE


C supports another function called puts() to display line of characters,

Syntax:

puts(variablename);

Eg:

puts(fullname);

Example
57

 STRING HANDLING FUNCTIONS


There are certain function to manipulate a given string. Before using those functions,
the header file “string.h” must be included in the program.

Syntax:

#include<string.h>

1. strcmp() : String Comparison

This function is used to compare the two given strings are equal or not. It
return 0 when the given strings are equal.

Syntax:

strcmp(string1,string2);

2. strcpy() : Syring Copy

This function is used to store right side contained string to left side.

Syntax:

strcpy(string1,string2);

Copy string2 to string1. string1’s value replaced.

3. strlen() : Syring Length

This function is used to find the length of a string. That means, it return the
number of characters in a given string. It also include space.

Syntax:

strlen(string);

Eg:

strlen(“snc vtk”);

Result : 7
58

4. strcat() : String Concatenation

This function is used to join two strings together.

Syntax:

strcat(string1.string2)

Eg:

strcat(“haii”,”hello”);

result: haiihello

 STRUCTURES
C Supports a constructed data type called structure. A structure is a powerful
tool to store data values of different types. That means, unlike an array a structure can
store integer, floating, character etc data values in a single unit.

 DEFINING A STRUCTURE
The keyword struct is used to define a structure. The structure contains a
structure name (structure tag), structure members and a structure variable.

Structure name indicates the name of a structure. Structure members represent


the variable inside the structure. And the structure variable is used to access the
structure members.

Syntax

struct structure_tag

datatype variables;

datatype variables;

…………..

};
59

Eg:

struct book

char title[50];

char author[25];

int pages;

float price;

};

 STRUCTURE VARIABLE
It is used to access the members of a structure. In C program structure variable
can create in two ways.

1)

struct structure_tag

datatype variables;

datatype variables;

…………..

}structurevariable;

2) struct structure_tag structure_variable;


60

Example

struct book

char title[50];

char author[25];

int pages;

float price;

} b1,b2;

 ACCESSING STRUCTURE MEMBERS


To access structure members use dot operator (period operator) along with
structure variable.

Syntax:

svariable.variable=value;

scanf(“controlstring”,&svariable.variable);

printf(“controlstring”,svariable.variable);

NB: svariable indicates : structure variable.


61

Example

 UNIONS
Unions are concept borrowed from structure and therefore follow the similar
syntax as structure. Use the keyword union. Like structure union variable is used to
access the union members.

However, there is major distinction between them in terms of storage location.


In structure, each member has its own storage location, whereas all members of union
use the same storage location. A union may contain members of different types, but it
can handle only one member at a time. In union take largest size among all members.

Example

 Structure Members :

rollno : integer : 2 bytes

name : character : 1 byte

avg_mark : float : 4 bytes

All three have individual location.

 Union Members:

rollno : integer : 2 bytes

name : character : 1 byte


62

avg_mark : float : 4 bytes

All three have same location

 Take largest location among all members.

 So, here the size of the union is 4.

Syntax:

union union_name

datatype variable1;

datatype variable2;

………….

} union_variable;

union student

int rollno;

float avg_mark;

char gender;

} s1;

Size: 4

 ACCESSING UNION MEMBERS


To access union members use dot operator (period operator) along with union
variable.
63

Syntax:

unionvariable.variable=value;

scanf(“controlstring”,&unionvariable.variable);

printf(“controlstring”,unionvariable.variable);

Example:

scanf(“%d”,&s1.rollno);

printf(“%d”,s1.rollno);
64

Module-4
 USER DEFINED FUNCTION

C functions can be classified into two categories. Library function and user
defined function. The difference is, library functions are not required to be written by
programmer, where as user-defined function are to be written by the programmer.

The program may become too large and complex as of a result the task of
debugging testing etc become difficult. If a program is divided into functional parts
then each part may be independently coded and later combined into a single unit.
These independently coded programs are called sub programs that are much easier to
understand in C. Such sub programs are called Functions.

MULTI FUNCTION PROGRAM

A function is a self contained block of code that performs a particular task. A


program that contains two or more sub functions is called multi function program.

 ADVANTAGES

1. Reduction in Program Size: Since any sequence of statements which are


repeatedly used in a program can be combined together to form a user defined
functions. And this functions can be called as many times as required. This
avoids writing of same code again and again reducing program size.
2. Reducing Complexity of Program: Complex program can be decomposed
into small sub-programs or user defined functions.
3. Easy to Debug and Maintain : During debugging it is very easy to locate and
isolate faulty functions. It is also easy to maintain program that uses user
defined functions.
4. Readability of Program : Since while using user defined function, a complex
problem is divided in to different sub-programs with clear objective and
interface which makes easy to understand the logic behind the program.
5. Code Reusability : Once user defined function is implemented it can be called
or used as many times as required which reduces code repeatability and
increases code reusability.
65

 ELEMENTS OF USER DEFINED FUNCTIONS


1) Function Declaration
2) Function Call
3) Function Definition

FUNCTION DECLARATION

All functions in C must be declared like variables, before they are invoked
(called). It consists of the following parts:

a) Function type(return type)


b) Function name
c) Parameter list(argument list)
d) Semicolon

Syntax:

returntype functionname(argument list);

Eg:

void display();

int add();

float sub(int,int);

FUNCTION CALL

A user defined function must be called externally by the programmer. A


function can be called by simply using the function name followed by a list of
argument.

Syntax:

functionname(argument list);
66

Eg:

display();

In the time of function call, the control of the program is transferred to the called
function. After the execution of function is completed it transferred back to the
calling area.

FUNCTION DEFINITION

When calling a function the corresponding code will executed for the program.
That program block is called function definition. It consists of following parts:

a) Return type
b) Function name
c) Parameter list(argument list)
d) Variable declaration\

Syntax:

returntype functionname(parameter list)

variable declaration;

program statements;

…………………..

……………………

return statement;
}
67

Eg:

void display()

int a=10;

printf(“a=%d”,a);

RETURN VALUE

A function may or may not send back any value to the calling function. If it
sends, it is done by the return statement.

Syntax:

return value/variable;

The return value goes to the calling function with corresponding return type. The
return type of the function is based on the return value.

Types:

1- void : if function returns no value


2- int : if the function returns an integer value
3- float : if the function returns a fractional value
4- char : if the function returns a character value
68

Example

 CATEGORY OF FUNCTION
Argument : value passed to the user defined function

Return value: value passed to the calling side from user defined function

Argument : any type, any number

Return value : any type, any number

Based on the number of arguments and return type a user defined function can
be categorized into the following:

1) Function with no argument and no return value


2) Function with arguments and no return value
3) Function with argument and one return value
4) Function with no argument but return value
5) Function that return multiple values
69

Function with no argument and no return value

When a function has no argument, it does not receive any data from the calling
function. Also when it does not return a value, the calling function does not receive
any data from the called function.

Syntax:

void functionname()

………………………

…………………………

}
70

Function with arguments and no return value

Here, the function does not return any value. But the calling function is send
some arguments to the called function.

Syntax:

void functionname(arguments)

……………………

…………………….

………………………

}
71

Eg:

Function with argument and one return value

In this type of function, two way communication process is occur. That means,
when calling the function there should transmit a value to the called function and after
the execution of called function it returns a value back to the calling side.

Syntax:

returntype functionname(arguments)

……………………

…………………….

………………………

}
 Return integer value

int functionname(…)
72

 Return floating value

float functionnanme(…..)

 Return character value

char functionname(….)

Eg:

Function with no argument but return value

This type of function consists of no argument list in the time of call. But after
the execution of function it returns a value back to the calling side.

Syntax:

returntype functionname()

……………………

…………………….

………………………

return value

}
73

Eg:

Function that return multiple values

The mechanism that is used in the C program for return multiple value is by
using the address operator(&), which indicates the address of the given variable
names.
74

Eg:
75

NESTING OF FUNCTION

Nesting of function means that a function contains another function. C permits


these types of functions.

Syntax:

returntype function1(argument list);

returntype function2(argument list);

void main()

………………………….

function1();

…………………………

returntype function1(argument list)

{ …………………

function2();

………………….

returntype function2(argument list)

…………………………..

Here the main function calls the sub function named function1(), and in the
execution of first function it calls the second sub function named function2().
76

Eg:

CHAINING

When a function calls another function, and it calls some another function and
so on, this process of calling is known as chaining.

RECURSION

Recursion is a special case of chaining process, where a function calls itself.


Such functions are known as recursive function.
77

Syntax:
returntype function1(argument list);

void main()

………………………….

function1();

…………………………

returntype function1(argument list)

{ …………………

function1();

………………….

Eg:
78

 Output

Enter the number

Numbers in descending order!

 ARGUMENT PASSING MECHANISM


We already saw that variables are passed to the function as argument in
different ways (categories of function). Here we point out the 2 types of function
call , one is the normal value passing & the other is based on address.

They are

1) CALL BY VALUE (PASS BY VALUE)


2) CALL BY REFERENCE (PASS BY REFERENCE)

It can be obtained by the use of 2 arguments

actual argument.

 Argument that passed to the function definition is called actual argument.

Eg:

int a,b;

display(a,b);
79

Here the a,b variables are actual

Formal Argument

 Argument that received in the function definition is called formal argument.

 Eg:

void display(int x, int y)

Here x,y are formal argument

a) Actual Argument  passing argument (eg: sum(a);)


b) Formal Argument  receiving argument (eg: void sum(int x))
Here ‘a’ is actual argument and ‘x’ is formal argument

CALL BY VALUE

The process of passing actual value of the variable is called call by value. Here
when passing the argument, only one copy of that variable is passed to the called
function. So if there any change made in the formal argument occurred in the function
definition, it will note affected in the actual arguments.

Eg:

#include<stdio.h>

#include<conio.h>

void sample(int);

void main()

int a;

clrscr();

printf(“Enter the number\t”);

scanf(“%d”,&a);
80

sample(a); //Actual argument

print(“a=%d”,a);

getch();

void sample(int x) //Formal arguemnt

x=x+2;

printf(“x=%d\n”,x);

OUTPUT

Enter the number 4

x=6

a=4

here the value of the variable ‘a’ didn’t change after the execution of sample()
function. It remains the same.

CALL BY REFERENCE

The process of calling a function using pointers to pass the address of the
variables is known as call by reference. The function which is called by reference can
change the value of the variable used in the call(actual variable).

Eg:

#include<stdio.h>

#include<conio.h>

void sample(int *);


81

void main()

int a;

clrscr();

printf(“Enter the number\t”);

scanf(“%d”,&a);

sample(&a); //Actual argument

print(“a=%d”,a);

getch();

void sample(int *x) //Formal argument

*x=*x+2;

printf(“x=%d\n”,*x);

OUTPUT

Enter the number 4

x=6

a=6

Here the value of the variable ‘a’ changed after the execution of sample() function. It
remains the same of the formal argument, because here pass the address along with
the value. So changes can be made.
82

 STORAGE CLASSES
C supports a verity of variables in the program coding. The scope, visibility
and life time of these variables are different.

1. Automatic Variable
2. External Variable
3. Static Variable
4. Register Variable

AUTOMATIC VARIABLE

They are declared inside a function in which they are to be utilized. They
created automatically when the function is called and destroyed automatically when
function is exited. They are also known as local variable or internal variable. It may
use the keyword auto.

Scope: inside a function or block

Visibility: only in that function or block

Life time: end of function

Syntax:

datatype variablename;

or

auto datatype variablename;

Eg:

int a;

auto int b;
83

Example

EXTERNAL VARIABLE

Variables that are active throughout the entire program are known as external
variable. It is also known as global variable. It can be accessed not only the specific
function but also by any function in the program. They are declared outside the
function. It may use the keyword extern.

Syntax:

datatype variablename;

or

extern datatype variablename;


84

Eg:

int a;

extern int c;

Scope: entire program

Visibility: entire program

Life time: end of program

Example
85

STATIC VARIABLE

The variable value persists until the end of the program as it declared as static.
It can be declared using the keyword static.

Syntax:

static datatype variablename;

Eg: static int a;

It can be either local type or global type;

Local Type:

Scope: inside a function or block

Visibility: only in that function or block

Life time: end of program

Global Type:

Scope: entire program

Visibility: entire program

Life time: end of program


86

Example
87

REGISTER VARIABLE

To kept the variable in one of` the machine’s register, we use the register
variable. It can be declared using the register keyword.

Syntax:

static datatype variablename;

Eg:

register int b;

Scope: inside a function or block

Visibility: only in that function or block

Life time: end of program


88

Module-5

 POINTERS
1- UNDERSTANDING POINTERS

The computer’s memory is a sequential collection of storage cells. Each


cell, commonly known as a byte, has a number called address associated with it.
The addresses are numbered consecutively, starting from zero. The last address
depends on memory size.

Memory cell & address

.
.
.
.
.
.
.
.
.
65789
89

“A pointer is a variable that can hold address of another variable”

Whenever we declare a variable, the system allocates somewhere in the memory,


an appropriate location to hold the value of the variable. Since, every byte has a
unique address number, this location will have its own address number.

Eg: int quantity=179;

Representation

quantity ← variable

179 ←value

5000 ←address

“ Variables that hold memory addresses are called pointer


variables. A pointer variable is nothing but a variable that contains
an address , which is a location of another variable in memory.”
Control string => %u

2- ACCESSING THE ADDRESS OF A VARIABLE

The actual location of a variable in the memory is system dependent and the
address of a variable is not known immediately. This can be done with the help of
the operator & available in C. It is already used in the scanf function in C. The
operator & immediately preceding a variable returns the address of the variable
associated with it.

Eg:

p=&quantity;

It would assign the address of the variable quantity(5000) to the variable p.

& - address of
90

3- DECLARING POINTER VARIABLE

Syntax :

datatype *pointer_name;

Eg :

int *p; // integer pointer

float *q; //floate pointer

4- INITIALIZATION OF POINTER VARIABLE

The process of assigning the address of a variable to a pointer variable is


known as initialization. Once a pointer variable has been declared we can use the
assignment operator to initialize the variable.

Eg:

int quantity;

int *p;

p=&quantity;

here the variable p holds the address of the another variable quantity.

5- ACCESSING A VARIABLE THROUGH ITS POINTER

If a pointer has been assigned the address of a variable using pointer, and we
want to access its value, C support an operator * . Consider the following code

int quantity, *p, n;

quantity= 179;
91

p= &quantity;

n=*p;

here the variable the variables holds the values as follows:

quantity - 179

p - 5000(address of the variable quantity)

n - 179

here n=*p means, it hold the value of that location.

6- POINTER EXPRESSIONS

Like the other variables pointer variables can be used in expressions. All
arithmetic , increment, decrement etc operation should perform with the pointer
variables. Here the data types of each variable should match.

Eg:

Y=*p1+*p2;

E=sum+*t1;

*p=*p1++;

*u=10+*t;

7- POINTERS AND ARRAY

When an array is declared, the compiler allocates a base address and


sufficient amount of storage to contain all the elements of the array in contiguous
memory location. We can access its location through & operator.

Eg:

int x[5]={1,2,3,4,5};

int *p;
92

p=&x[0];

p hold the address of 1st array location.

 FILE MANAGEMENT
A file is a place on the disk when a group of related data is stored. C
supports a number of functions that have the ability to perform basic file
operations. These includes:

1) Naming a file/Defining a file


2) Opening a file
3) Reading data from file
4) Writing data to file
5) Closing a file

Defining and opening a file

To perform operations on file, first open the file for that purpose. It
includes:
a) Filename
b) Data structure
c) Purpose

Declaring a file

Syntax:

FILE *filepointer;

Eg:

FILE *f1;

FILE *f2,f3;
93

File pointer is the pointer to the data type FILE.

Opening a file

To the purpose fopen() is used.

Eg:

FILE *fp;

fopen(“filename”,”mode”);

It opens the named file and assign the file pointer fp to the file location.

MODE
It specifies the purpose of opening the file. The mode can be on the
following:’

1) r = Open the file for reading only


2) w = Open the file for writing only
3) a = Open the file for appending.

Eg:

FILE *f1;

fopen(“data”,”r”); // opened for reading

fopen(“data”,”w”); //opened for writing.

Closing a file

A file must be closed as soon as all operations on it have been completed.


After this operation all associated data links to the file are broken. To use this
fclose() function for this purpose.

Syntax:

fclose(filepointer);
94

Eg:

fclose(f1);

INPUT OUTPUT OPERATIONS ON FILE

1) Character Input Output


To read & write character to and from a file, C supports 2 types of
functions. These are similar to the getchar()&putchar(),handling one
character at a time.

a) putc(
) Suppose a file is opened with write mode(w) and the file pointer is f1.
Then if we want to write a character to that file =>
putc(c,f1);
here, c indicates the variable that hold the single character.

b) getc(
) Suppose a file is opened with read mode(r) and the file pointer is f1.
Then if we want to read a character from the file =>

c=getc(f1);
the getc(f1) read a single character from the file f1 and it stored to the
another variable c.

2) Integer Input Output


To read and write integer values in a file , C supports 2 types of
functions:
a) putw()
Used to write an integer value to the specified file.
o putw(num,f1);
95

here f1 is the file pointer, num is the integer value that write to the
file.

b) getw()
Used to read an integer value from the specified file.
o Num=getw(f1);

Here getw() read an integer value from the f1 pointed file and stored
into the variable Num.

INPUT OUTPUT MORE THAN 1 CHARACTER OR INTEGER

1) fprintf()
It is similar to printf() function. But here specifies the file pointer also.
Syntax:
fprintf(fp,”controlstring”,list);
Eg:
fprintf(f1,”%d%f”,num,ratio);

2) fscanf()
Similar to the scanf() function. But here specifies the file pointer also.
Syntax:
fscanf(fp,”controlstring”,list);
Eg:
fscanf(fp,”%d”,&num);

EOF -END OF FILE

It indicates the end of the file. That is the last content of a file is indicated.
96

DYNAMIC MEMORY ALLOCATION

In a computer system, memory allocation are of 2 types.

1) Static
2) Dynamic
In static allocation, no additional memory are allocated during running a
program and no extra memory can release to that time.
Eg: Array
In Dynamic, these 2 operations can be performed.
Eg: Linked List.

Memory Allocation Process

Dynamic Allocation

The process of allocating memory of runtime is known as Dynamic memory


allocation. C supports some arrangement functions to acquire these functionalities.
97

1) malloc()
Allocates requested size of memory. Here, a block of memory may be
allocated using the function malloc(). It reserves a block of memory
that specifies the space.

Syntax:

ptr= (type *) malloc(size);

eg:

p=(char *)malloc(10);

2) calloc()
It is normally used for requesting memory space of runtime for storing array
and structure. It is used to allocate multiple blocks of memory.
Syntax:
ptr=(type *)calloc(n,size);
eg:
ptr=(record *)calloc(class_size,sizeof(record));
here record=> structure variable.

3) Free ()

To release the unwanted space during execution time use the free()
function.
Syntax :

free(ptr);

Eg: free(p);

p-> pointer variable.


98

4) realloc()
The previously allocated memory is not sufficient and need to
additional space for more element, C supports the realloc()
function. Syntax:
ptr=malloc(size);
ptr=realloc(ptr,newsize);

Eg:

ptr=malloc(20);

ptr=realloc(ptr,40);

You might also like