0% found this document useful (0 votes)
6 views54 pages

Notes PPS

Uploaded by

venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views54 pages

Notes PPS

Uploaded by

venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE

KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

I B.Tech I- Semester

Programming for Problem Solving


(R18) 2020-21

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 1


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

UNIT - I
Computer Systems
A computer is a system which has two major components: hardware and software.
The computer hardware is the physical equipment. The software is the collection of
programs (instructions) that allow the hardware to do its job.

Computer Hardware
The hardware of the computer system is group of five parts: input devices, central
processing unit (CPU), primary storage, output devices, and auxiliary storage devices.

Generally a keyboard is the popular input device. The programs and data are entered into the
computers using key board. Other input devices are mouse, a pen or stylus, a touch screen,
or an audio input unit.

The central processing unit (CPU) is executes instructions such as arithmetic calculations.
Present generation computers may have one, two, or more CPUs.

Primary storage is also known as main memory. This is a place where the programs and
data are stored temporarily during processing. The data in primary storage is removed when
we turn off a computer.

The output device is generally a monitor or a printer. The output is shown on the monitor is
called as soft copy. If output is a printed one is called hard copy.

Auxiliary storage, (secondary storage), is used for both input and output. It is the place
where the programs and data are stored permanently. When we turn off the computer the
programs and data remain in the secondary storage which can be used again when user need
them.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 2


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Computer Software

Computer software is divided in to two categories.


 system software and
 application software.
Application software, is used by the users to solve their problems.

System software manages the computer resources. It provides the interaction between the
hardware and the users. These programs are divided into three classes: the operating system,
system support, and system development.

The operating system provides services such as a user interface, file and database access,
and interfaces to communication systems such as Internet protocols.

System support software provides system utilities and other operating services.

System development software includes the compilers and debuggers.

Application software belongs to two classes: general-purpose software and application –


specific software. General purpose software is purchased from a software developer and
can be used for more than one application. Example: MS Office etc.

Application –specific software can be used only for specific purpose.


Example: A general ledger system used by accountants.

Computing Environments
The different types of computing environments are
1. Personal Computing Environment
2. Time-Sharing Environment

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 3


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


3. Client/Server Environment
4. Distributed Computing

1. Personal Computing Environment


In 1971, Marcian E.Hoff, working for Intel, combined the basic elements of the
central processing unit into the microprocessor. The first computer on a chip was the Intel
4004 and was the grandparent many times removed of Intel’s current system.

If we are using a personal computer, all of the computer hardware components are
grouped together in our personal computer (PC).

2. Time-Sharing Environment
Employees in large companies often work in what is known as a time-sharing
environment. In the times-sharing environment, many users are connected to one or more
computers. These computers may be minicomputers or central mainframes. The terminals
they use are often nonprogrammable, although today we see more and more
microcomputers being used to simulate terminals. Also, in the time-sharing environment,
the output devices and auxiliary storage devices are shared by all of the users. A typical
college lab in which a minicomputer is shared is shared by many students is shown in
figure:

In the time-sharing environment, all computing must be done by the central computer. The
central computer has many duties: It must control the shared resources; it must manage the
shared data and printing and it must do the computing.
3. Client/Server Environment

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 4


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


A client/server computing environment splits the computing function between a
central computer and users’ computers. The users are given personal computers or work
stations so that some of the computation responsibility can be moved from the central
computer and assigned to the workstations. In the client-server environment, the users’
micro computers or workstations are called the client. The central computer, which may be
a powerful microcomputer, minicomputer, or central mainframe system, is known as the
server. Because the work is now shared between the users’ computers and the central
computer.

4. Distributed Computing
A Distributed Computing environment provides an integration of computing
functions between different servers and clients .The internet provides connectivity to
different servers throughout the world. For example eBay uses several computers to provide
its auction services. This environment provides a reliable, scalable, and highly available
network.

Fig: Distributed Computing


Computer Languages
To write a program for a computer, we must use a computer language. Over the
years computer languages have evolved from machine languages to natural languages.
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 5
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


1940’s Machine level Languages
1950’s Symbolic Languages
1960’s High-Level Languages

Machine Languages
In the early days of computers, the programming languages available were only
machine languages. Each computer has its own machine language, which is made by
grouping 0’s and 1’s. The only language understood by computer hardware is machine
language.

Symbolic Languages:
In early 1950’s Admiral Grace Hopper, A mathematician and naval officer
developed Symbolic Language; a special computer program that would convert symbolic
code into machine language is called Assembler.
Symbolic language uses symbols or mnemonics to represent the various, machine language
instructions.
High Level Languages:
High level languages are portable to many different computers. High level languages
share one thing with symbolic languages; They must be converted into machine language.
The process of converting them is known as compilation.
The first widely used high-level languages, FORTRAN (FORmula TRANslation)
was created by John Backus and an IBM team in 1957. After FORTRAN was COBOL
(Common Business-Oriented Language). Admiral Hopper was played a key role in the
development of the COBOL Business language.
C is a high-level language used for system software and new application code.
Creating and Running Programs
Computer hardware understands a program only if it is coded in its machine
language. It is the job of the programmer to write and test the program .There are four steps
in this process:
1. Writing and editing the program
2. Compiling the program
3. Linking the program with the required library modules
4. Executing the program.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 6


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 7


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Writing and Editing Programs


The software used to write programs is known as a text editor. After completing a
program, we save our file to disk. This file will be input to the compiler; it is known as a
source file.

Compiling Programs:
The code in a source file must be translated into machine language. This is the job of
the compiler. The c compiler is two separate programs-preprocessor and the translator.

The preprocessor reads the source code by scanning preprocessor commands and
replacing with special code libraries by finally preparing it for the translator.

After the preprocessor has prepared the code for compilation, the translator does the
actual work of converting the program into machine language.

Linking Programs:
A C program is made up of many functions. We write some of these functions, and
they are a part of our source program. There are other functions, such as input/output
processes and, mathematical library functions that exist elsewhere and must be attached to
our program. The linker assembles all of these functions, ours and systems into our final
executable program.

Executing Programs:
Once program has been linked, it is ready for execution. To execute a program we
use an operating system command, such as run, to load the program into primary memory
and execute it. Getting the program into memory is the function of an operating system
program known as the loader.
After the program processes the data, it prepares the output and the output can be to the
user’s monitor or to a file.

PROGRAM DEVELOPMENT STEPS:


Program Development is a multistep process that requires that we understand the
problem, develop a solution, write the program, and then test it. This is known as program
design.

Understand the Problem


The first step in solving any problem is to understand it. By reading the requirements
statements carefully, we fully understand it; we review our understanding with the user and
the systems analyst to know the exact purpose.

Develop the solution

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 8


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Once we fully understand the problem we need to develop our solution. Three tools
will help in this task. 1. Structure chart, 2.Psuedocode &3.Flowcharts. Generally we will use
structure chart and either flowchart or Pseudo code

The structure chart is used to design the whole program .


Pseudo code and flowcharts are used to design the individual parts of the program.
Structure chart: A structure chart, also known as hierarchy chart, shows the functional
flow through our program. The structure chart shows how we are going to break our
program into logical steps each step will be a separate module.

We can use flowchart or pseudo code to complete the design of your program.

Write the program


We will write the programs by using structure chart and flowchart or pseudo code.
This is known as top-down implementation.

Test the Program


Programmer is responsible for completely testing the program. In large-
development projects test engineers are responsible for testing to make sure all the programs
work together.
There are 2 types of testing.

1. Black box testing: This is done by the system test engineer and the user. Black box
testing is the programs are tested without knowing what is inside it, without knowing
how it works. Black box test plans are developed by looking only the requirements
statement. The test engineer uses these requirements to develop test plans.

2. White box testing: This is the responsibility of the programmer. White box testing
assumes that the tester knows everything about the program.

ALGORITHM /PSEUDOCODE:

1. Pseudo Code:

Pseudo-code is the way of writing the steps to solve a problem in any spoken language like
English. Pseudo-code is informal language that used to develop algorithms. It is not a
computer programming language like C. It helps the programmer to develop programs.
2. Algorithm:

Describing the process step-by-step is called algorithm. OR An algorithm is a finite set of


instructions that, if followed, accomplishes a particular task.
For any given problem, we have more than one algorithm to solve it. We should select the
best among all possible algorithms. The algorithm which solves the problem fast by using
minimum resources to be selected.

Steps in the algorithm: An algorithm can be divided into three basic categories.

 Sequence: A series of steps that we perform one after other.


Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 9
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


 Decision: Some selected and some are ignored.
 Selection: Making a choice from multiple available options.
 Iteration: Performing repetitive tasks.

Performance: The performance of an algorithm is measured by using Space complexity &


Time complexity

Space complexity of an algorithm is the amount of memory it needs to run to completion.


Time complexity of an algorithm is the amount of computer time it needs to run to
completion.

The algorithm which as best space complexity and/or time complexity should be selected to
solve the problem based on context.

Example: Algorithm/pseudo code to add two numbers


Step 1: Start
Step 2: Read the two numbers in to a, b
Step 3: c=a+b
Step 4: write/print c
Step 5: Stop.

FLOW CHART:
A Flow chart is a Graphical representation of an Algorithm. Flow charts are drawn
using certain special purpose symbols such as Rectangles, Diamonds, Ovals and small
circles. These symbols are connected by arrows called flow lines.
(or)
The diagrammatic representation of way to solve the given problem is called flow chart.

Symbol Symbol Name Usage Usage Description


Used to represent Start or
Oval Terminal
Stop/end of algorithm
Used to represent
Rectangle Process processing data or
assignment
Used to represent input or
Parallelogram Data
output data
Used to represent
Diamond Decision selection or Conditional
statement
Used to represent the
Circle Connector joining of more than one
flow into one
Used to represent flow of
Arrow Flow execution by joining
symbols

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 10


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Uses of flow charts: The following are the basic uses of flow charts.

 Defining and analyzing processes.


 Building a step-by-step picture of the process for analysis, discussion, or
communication purposes.
 Defining, standardizing, or finding areas for improvement in a process.

INTRODUCTION TO ‘C’ LANGUAGE:

C is a general purpose, high level, structured programming language.

HISTORY OF ‘C’ LANGUAGE:

C language was developed by Dennis Ritchie, in 1972 at AT&T (American Telephones &
Telegraphs) Bell Labs, New-Jersy, USA.

ADVANTAGES OF ‘C’ LANGUAGE:

 C language has rich set of built-in functions and operations that can be used to write
any difficult program.

 C language is suitable for writing both system software and business packages.

 Programs written in ‘C’ are efficient and fast. This is due to its variety of data types
and powerful operators.

 There are only 32 keywords in ANSI C and its strength lies in its build-in functions.

 C is highly portable. This means that C programs written for one computer can be
run on another computer with little or no modifications.

 C language is well suited for structured programming. User can solve problems in
terms of function modules or blocks.

 A ‘C’ program is basically a collection of functions that are supported by the C


library.

STRUCTURE OF A ‘C’ PROGRAM:


A ‘C’ program may contain one or more sections as…

Documentation Section
Link Section
Definition Section
Global Declaration
Section
Main () Function Section
{
Declaration part
Executable part
}
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 11
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Sub-program Section
Function-1
Function-2
.........
.........
Function-n

The documentation section consists of a set of comment lines such as giving the name of the
program, the author and other details. All the comments of a C program must be written
between /* and */.
Eg: /* This is my first program */
The link section provides instructions to the compiler to link functions from the system
library.

Eg: #include <stdio.h>

The definition section defines all the symbolic constants.


Eg: #define PI 3.14

The global declaration section is used declare global variables of a C program. Global
variables are used at any part of the program.
Every C program must have one main () function section. This section contains two parts,
declaration part and process part. The declaration part is used to declare all the variables
used in the process part. There must be atleast one statement in the process part. These two
parts must appear between the opening and the closing braces. All statements in the
declaration and executable parts end with a semicolon ; .

The subprogram section contains all the user-defined functions that are called in the main()
function.

All sections, except the main() function section may be absent in the program when they are
not required.

Creating and Running Programs:

There are four steps in this process of creating and running programs:

1. Writing and Editing the program


2. Compiling the program
3. Linking the program with the required library functions
4. Executing the program.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 12


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Writing and Editing Programs:

A text editor is software used to write or modify the program. The program file is saved to
disk with a file name of extension .C. For example, add.c. This file is also known as source
file.

Compiling Programs:
Compiler is a software used to convert C program source file into machine language. The
compiler checks the program for any syntax errors. The c compiler is two separate programs
preprocessor and the translator. The preprocessor reads the source code by scanning for
special instructions known as preprocessor commands(contains # symbol). These commands
tell the preprocessor to look for special code libraries, make substitutions in the code, and
generate .obj file (object file).Then the translator convert .obj file into machine readable file
called executable file.

Linking Programs:

In a C program, we may write some of the functions like printf, scanf, sqrt etc. The linker
links these functions to our program from header files. Assemble all of these functions,
related to program and system into our final executable program.

Executing Programs:

Once program has been linked, it is ready for execution. To execute a program we use an
operating system command, such as run.

Constants, Variables and Data Types

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 13


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

CHARACTER SET:

The following are the character that can be used to form words, numbers and expressions
depend upon the computer on the program is run. They are…

 Alphabets (A – Z and a – z)
 Numerals (0 – 9)
 Special Characters ( ~ ! # $ % ^ & * ( ) _ - + = [ ] { } | \ ; : ‘ “ , < . > / ?)

1. C TOKENS:

C tokens are the basic buildings blocks in C language which are constructed together to
write a C program.

Each and every smallest individual units in a C program are known as C tokens.

C tokens are of six types. They are,

1. Keywords (eg: int, while),


2. Identifiers (eg: main, total),
3. Constants (eg: 10, 20),
4. Strings (eg: “total”, “hello”),
5. Special symbols (eg: (), {}),
6. Operators (eg: +, /,-,*)
Word: A word is a collection of characters which has some meaning. The following are the
rule to form a word.
 A word can be formed with the help of 37 characters only.
o Alphabets (A – Z & a – z) (26)
o Numerals (0 – 9) (10)
o Underscore ( _ ) (1)
 The length of the word should not exceed 8 characters.
 A word must start with the alphabet only.
 A word must not start with a numeral but it can end with a numeral.
 Underscore is used to separate the words.

Words are broadly categorized into two types. They are i) Reserved words and ii) User-
defined words.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 14


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


1.1. Reserved words or Keywords: Reserved words are the words which are syntactically
and semantically defined by the language. Some of the reserved words are given below.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

User-defined words: User-defined words are the words which are defined by the user for
his specific purpose.

Eg: marks, emp_sal;

1.1. Identifiers: An identifier is a name, which was given to the element of a program
such as names of the variables, constants, functions, structures, unions pointers, files
etc.,

Variables: A variable is an identifier, which reserves some space in the memory, which can
change its value during the execution of a program.

Eg: marks, emp_sal;

1.2. Constants: A constant is an identifier, which reserves some space in the memory,
which cannot change its value during the execution of a program. Constants can be
broadly categorized into two types. They are i) Character constants ii) Numeric
constants.

Character constants: Character constants can be formed with the help of valid ‘C’
character set. They can be a) Single character constants and b) String constants.

Single character constants: Single character constants are the single characters enclosed
within single quotations.
Eg: ‘a’, ‘*’, ‘5’

String constants: String constants are the collection of characters enclosed within double
quotations.

Eg: “H.No. 3-7-137”

Numeric constants: Numeric constants can be formed with the help of numbers only. They
can a) Integer constants b) Real Constants.

Integer constants: An integer constant is a sequence of digits with or without sign, without
decimal point or exponentiation.

Eg: 123, -234

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 15


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Real constants: A real constant is a sequence of digits with or without sign, with a decimal
point or exponentiation.

Eg: 123.45, -123.45

Backslash Character Constants: C supports some special back slash character constants
that are used in output functions. These characters combinations are known as ‘escape
sequences’.

Constant Meaning
‘\a’ Audible alert
(bell)
‘\b’ Back space
‘\f’ Form feed
‘\n’ New line
‘\r’ Carriage return
‘\t’ Horizontal tab
‘\v’ Vertical tab
‘\’’ Single quote
‘\”’ Double quote
‘\?’ Question mark
‘\\’ Backslash
‘\0’ Null

DATA TYPES:

C supports different types of data, each of which may be represented differently within a
computer's memory. Data type is used to determine what type of value a variable or a
constant can contain throughout the program. Data types of the ‘C’ language are…

 Primary (or fundamental) data types


 User-defined data types
 Derived data types
 Empty data set

Primary Data Types: All C compilers support four fundamental data types such as
Character (char), integer (int), floating point (float) and double floating point (double).

Character data type: Character data type is used to represent character type of information.
Different character data types, their size and memory requirements are…

Memory
Sl. No. Data Type Range of values
Size
1 Signed char -128 to 127 1 byte
2 Unsigned char 0 to 255 1 byte

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 16


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Integer Data Types: An integer is a sequence of digits, with or without sign, without
decimal point or exponentiation. Different integer data types, their size and memory
requirements are…

Memory
Sl. No. Data Type Range of Values
Size
Signed Short int (Short
1 -128 to 127 1 byte
int)
2 Unsigned Short int 0 to 255 1 byte
3 Signed int (int) -32768 to 32767 2 bytes
4 Unsigned int 0 to 65535 2 bytes
Signed Long int (Long -2147483648 to
5 4 bytes
int) 2147483647
6 Unsigned Long int 0 to 4294967295 8 bytes

Floating Point Data Types: Floating point is a sequence of digits, with or without sign,
with a decimal point or exponentiation. Floating point numbers are stored in 32 bits with 6
digits of precision. Different floating point data types, their size and memory requirements
are…

Memory
Sl. No. Data Type Range of Values
Size
1 Floating point (float) 3.4E-38 to 3.4E+38 4 bytes

Double Floating Point Data Types: Double floating point is a sequence of digits, with or
without sign, with a decimal point or exponentiation. Double floating point numbers are
stored in 64 bits with 14 digits of precision. Different double floating point data types, their
size and memory requirements are…

Memory
Sl. No. Data Type Range of Values
Size
Double floating point
1 1.7E-308 to 1.7E+308 8 bytes
(double)
3.4E-4932 to
2 Long double 10 bytes
1.1E+4932

User-defined Data types: User defined data types of ‘C’ language are typedef and enum.

Typedef: C supports a feature known as “type definition” that allows users to define an
identifier that would represent an existing data type. It can be done as…

Syn: typedef data-type identifier;

Eg: typedef int marks;

Enum: C provides another user-defined data type is enumerated (enum). It is defined as…

Syn: enum identifier {val-1, val-2, … , val-n};

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 17


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Eg: enum day {sun, mon, tue, wed, thu, fri, sat};

The identifier is user-defined enumerated data type which can be used to declare variable
that can have one of the values enclosed within the braces. We can declare variables to be
of this ‘new’ type as…

Syn: enum identifier var-1, var-2, …, var-n;

Eg: enum day seek_st, seek_end;

The enumerated variables var-1, var-2, …, var-n can only have one of the values value-1,
value-2, … value-n. It can be done as…

Syn: var-2 = value-3;


Var-1 = value-5;

Eg: week_st = sun;


Week_end = sat;

Derived Data Types: Derived data types of ‘C’ language are arrays, functions, structures,
unions, pointers and files.

Empty Data Set: Empty data set of the ‘C’ language is ‘void’. Void means nothing.

DECLARATION OF VARIABLES:

After designing suitable variable names, we must declare them to the compiler. Declaration
does two things.

 It tells the compiler what the variable name is.


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

Syn: data-type var-1, var-2, …, var-n;

Var-1, var-2, …, var-n are the names of variables. Variables are separated by commas. A
declaration statement must end with a semicolon.

Eg: int count;


int number, total;
double ratio;

ASSIGNING VALUES TO VARIABLES:


Values can be assigned to variable using the assignment operator (=) as…

Syn: variable_name = constant;

Eg: x = 0;
y = 100;
balance = 75.45;

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 18


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


yes = ‘x’;
C permits multiple assignments in one line as…

Eg: x=0; y=100;

It is also possible to assign a value to a variable at the time the variable is declared as…

Syn: data-type variable_name = constant;

Eg: int x = 0;
char yes = ‘x’;
double balance = 75.45;

C permits the initialization of more than one variables in one statement using multiple
assignment operators as…

Eg: p = q = r = 0;

DEFINING SYMBOLIC CONSTANTS:

A symbolic constant in C can be defined by using #define pre-processor directive as…

Syn: #define symbolic_name value-of-constant

Eg: #define PI 3.14


#define MAX 100

Managing Input and Output Operations

Input means which the computer reads, and output means which the computer writes. The
C language input and output functions are broadly classified into 3 types. They are…

 Console Input and Output functions


 Disk Input and Output functions
 Port Input and Output functions

Console I/O functions are used to transfer the data between the program and console. Disk
I/O functions are used to transfer the data between the program and hard disk. Port I/O
functions are used to transfer the data between the program and computer port.

Console I/O functions are broadly classified into 2 types. Formatted console I/O functions
and unformatted console I/O functions.

Formatted Console I/O Functions: Formatted console I/O functions are used to read /
write mixed type from / to the console. The 2 formatted console I/O functions are printf( )
and scanf( ) functions.

printf() function: The printf() function is used to write mixed type data to the console.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 19


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Syn: printf(“control string”, arg-1, arg-2, …, arg-n);
Control string consists of three types of items such as…

a) Characters that will be printed on the screen as they appear.


b) Format specifications that define the output format for display of each item.
c) Escape sequence characters such as \n, \t and \b.

The control string indicates how many arguments follow and what their types are. The
arguments arg-1, arg-2, …, arg-n are the variables whose values are formatted and printed
according to the specifications of the control string. Commonly used printf format codes
are…

%c to print a single character


%d to print a decimal integer
%e to print a floating point value in exponent form
%f to print a floating point value without exponent
%g to print a floating point value either e-type or f-type depending on
%i to print a signed decimal integer
%o to print an octal integer, without leading zero
%s to print a string
%u to print an unsigned decimal integer
%x to print a hexadecimal integer, without leading Ox

Eg: printf(“Programming in C”);


printf(“ “);
printf(“\n”);
printf(“%d”, x);
printf(“a = %f\n b = %f”, a, b);
printf(“sum = %d”, 1234);
printf(“\n\n”);

scanf() function: The scanf() function is used to read mixed type data from the console.

Syn: scanf(“control string”, &arg-1, &arg-2, …, &arg-n);

The control string specifies the field format in which the data is to be entered and the
arguments arg-1, arg-2, …, arg-n specify the address of locations where the data is stored.
Commonly used scanf() format codes are…

%c to read a single character


%d to read a decimal integer
%e to read a floating point value
%f to read a floating point value
%g to read a floating point value
%h to read a short integer
%i to read a decimal, hexadecimal or octal integer

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 20


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


%o to read an octal integer
%s to read a string
%u to read an unsigned decimal integer
%x to read a hexadecimal integer
%[..] to read a string of word(s)

Eg: scanf(“%2d %5d”, &num-1, &num-2);


scanf(“%d %d”, &num-1, &num-2);
scanf(“%f %f %f”, &x, &y, &z);
scanf(“%d %c %f %s”, &count, &code, &ratio, name);

Unformatted Console I/O Functions: Unformatted console I/O functions are used to read
/ write character type of data from / to the console. The 7 unformatted console I/O functions
are getchar(), putchar(), getch(), putch(), getche(), gets(), puts().

getchar(): The getchar() function is used to read a single character from the console.

C – Operators and Expressions:

 The symbols which are used to perform logical and mathematical operations in a C
program are called C operators.
 These C operators join individual constants and variables to form expressions.
 Operators, functions, constants and variables are combined together to form
expressions.
 Consider the expression A + B * 5. where, +, * are operators, A, B are variables, 5
is constant and A + B * 5 is an expression.

Operator: C supports a rich set of built-in operators. An operator is a symbol, which


performs some operation. There are 8 types of operators in ‘C’ language.

Types of C operators:

1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical operators
5. Bit wise operators
6. Conditional operators (ternary operators)
7. Increment/decrement operators
8. Special operators

S.no Types of Operators Description


These are used to perform mathematical calculations
like addition, subtraction, multiplication, division
1 Arithmetic_operators and modulus
These are used to assign the values for the variables
2 Assignment_operators in C programs.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 21


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


These operators are used to compare the value of
3 Relational operators two variables.
These operators are used to perform logical
4 Logical operators operations on the given two variables.
These operators are used to perform bit operations
5 Bit wise operators on given two variables.
Conditional (ternary) Conditional operators return one value if condition
6 operators is true and returns another value is condition is false.
Increment/decrement These operators are used to either increase or
7 operators decrease the value of the variable by one.
8 Special operators &, *, sizeof( ) and ternary operators.

Arithmetic Operators in C:

 C Arithmetic operators are used to perform mathematical calculations like addition,


subtraction, multiplication, division and modulus in C programs.

S.no Arithmetic Operators Operation Example


1 + Addition A+B
2 – Subtraction A-B
3 * multiplication A*B
4 / Division A/B
5 % Modulus A%B

Example program for C arithmetic operators:

 In this example program, two values “40” and “20” are used to perform arithmetic
operations such as addition, subtraction, multiplication, division, modulus and output
is displayed for each operation.

#include <stdio.h>
int main()
{
int a=40,b=20, add,sub,mul,div,mod;
add = a+b;
sub = a-b;
mul = a*b;
div = a/b;
mod = a%b;
printf("Addition of a, b is : %d\n", add);
printf("Subtraction of a, b is : %d\n", sub);
printf("Multiplication of a, b is : %d\n", mul);
printf("Division of a, b is : %d\n", div);
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 22
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


printf("Modulus of a, b is : %d\n", mod);
}

Output:

Addition of a, b is : 60
Subtraction of a, b is : 20
Multiplication of a, b is : 800
Division of a, b is : 2
Modulus of a, b is : 0

Assignment operators in C:

 In C programs, values for the variables are assigned using assignment operators.
 For example, if the value “10” is to be assigned for the variable “sum”, it can be
assigned as “sum = 10;”
 Other assignment operators in C language are given below.

Operators Example Explanation


Simple assignment operator = sum = 10 10 is assigned to variable sum
+= sum += 10 This is same as sum = sum + 10
-= sum -= 10 This is same as sum = sum – 10
*= sum *= 10 This is same as sum = sum * 10
/+ sum /= 10 This is same as sum = sum / 10
Compound assignment
operators sum %= This is same as sum = sum %
%=
10 10
This is same as sum = sum &
&= sum&=10
10
^= sum ^= 10 This is same as sum = sum ^ 10

Example program for C assignment operators:

 In this program, values from 0 – 9 are summed up and total “45” is displayed as
output.
 Assignment operators such as “=” and “+=” are used in this program to assign the
values and to sum up the values.

# include <stdio.h>

int main()
{
int Total=0,i;
for(i=0;i<10;i++)
{

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 23


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Total+=i; // This is same as Total = Toatal+i
}
printf("Total = %d", Total);
}

Output:

Total = 45

Relational operators in C:

 Relational operators are used to find the relation between two variables. i.e. to
compare the values of two variables in a C program.

S.no Operators Example Description


1 > x>y x is greater than y
2 < x<y x is less than y
3 >= x >= y x is greater than or equal to y
4 <= x <= y x is less than or equal to y
5 == x == y x is equal to y
6 != x != y x is not equal to y

Example program for relational operators in C:

 In this program, relational operator (==) is used to compare 2 values whether they
are equal are not.
 If both values are equal, output is displayed as ” values are equal”. Else, output is
displayed as “values are not equal”.
 Note : double equal sign (==) should be used to compare 2 values. We should not
single equal sign (=).

Logical operators in C:

 These operators are used to perform logical operations on the given expressions.
 There are 3 logical operators in C language. They are, logical AND (&&), logical
OR (||) and logical NOT (!).

S.no Operators Name Example Description


logical
1 && (x>5)&&(y<5) It returns true when both conditions are true
AND
logical It returns true when at-least one of the
2 || (x>=10)||(y>=10)
OR condition is true

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 24


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


It reverses the state of the operand “((x>5)
logical && (y<5))”
3 ! !((x>5)&&(y<5))
NOT If “((x>5) && (y<5))” is true, logical NOT
operator makes it false

a b && || !a
False(0) False(0) 0 0 1
False(0) True(1) 0 1 1
True(1) False(0) 0 1 0
True(1) True(1) 1 1 0

0 1
1 0

Example program for logical operators in C:

#include <stdio.h>

int main() {

int a,b,c;

printf("enter a and b values\n");

scanf("%d%d",&a,&b);

c=(a>b && a==b);

printf("logical and result : %d\n",c);

c=(a>b || a==b);

printf("logical or result : %d\n",c);

c=!(a>b);

printf("logical not result : %d\n",c);

return 0;

Output:

enter a and b values

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 25


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


logical and result : 0

logical or result : 0

logical not result : 1

#include <stdio.h>
int main()
{
int m=40,n=20;
int o=20,p=30;
if (m>n && m !=0)
{
printf("&& Operator : Both conditions are true\n");
}
if (o>p || p!=20)
{
printf("|| Operator : Only one condition is true\n");
}
if (!(m>n && m !=0))
{
printf("! Operator : Both conditions are true\n");
}
else
{
printf("! Operator : Both conditions are true. " \
"But, status is inverted as false\n");
}
}

Output:

&& Operator : Both conditions are true


|| Operator : Only one condition is true
! Operator : Both conditions are true. But, status is inverted as false

 In this program, operators (&&, || and !) are used to perform logical operations on
the given expressions.
 && operator – “if clause” becomes true only when both conditions (m>n and m!
=0) is true. Else, it becomes false.
 || Operator – “if clause” becomes true when any one of the condition (o>p ||
p!=20) is true. It becomes false when none of the condition is true.
 ! Operator – It is used to reverses the state of the operand.
 If the conditions (m>n && m!=0) is true, true (1) is returned. This value is inverted
by “!” operator.
 So, “! (m>n and m! =0)” returns false (0).

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 26


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Bit wise operators in C:

 These operators are used to perform bit operations. Decimal values are converted
into binary values which are the sequence of bits and bit wise operators work on
these bits.
 Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise
OR), ^ (XOR), << (left shift) and >> (right shift).

Truth table for bit wise operation Bit wise operators

X y x|y x&y x ^ y Operator_symbol Operator_name


0 0 0 0 0 & Bitwise_AND
0 1 1 0 1 | Bitwise OR
1 0 1 0 1 ~ Bitwise_NOT
1 1 1 1 0 ^ XOR
<< Left Shift
>> Right Shift

 Consider x=40 and y=80. Binary form of these values are given below.

x = 00101000
y= 01010000

 All bit wise operations for x and y are given below.

x&y = 00000000 (binary) = 0 (decimal)


x|y = 01111000 (binary) = 120 (decimal)
~x = 11111111111111111111111111 11111111111111111111111111111111010111
.. ..= -41 (decimal)
x^y = 01111000 (binary) = 120 (decimal)
x << 1 = 01010000 (binary) = 80 (decimal)
x >> 1 = 00010100 (binary) = 20 (decimal)

Note:

 Bit wise NOT : Value of 40 in binary is 00000000000000000000000000000000


00000000000000000010100000000000. So, all 0’s are converted into 1’s in bit wise
NOT operation.
 Bit wise left shift and right shift : In left shift operation “x << 1 “, 1 means that the
bits will be left shifted by one place. If we use it as “x << 2 “, then, it means that the
bits will be left shifted by 2 places.

Example program for bit wise operators in C:

 In this example program, bit wise operations are performed as shown above and
output is displayed in decimal format.
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 27
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

#include <stdio.h>
int main() {
int x=42,y=20;
printf("bitwise and=%d\n",x&y);
printf("bitwise or=%d\n",x|y);
printf("bitwise xor=%d\n",x^y);
printf("bitwise leftshift=%d\n",x<<1);
printf("bitwise rightshift=%d\n",x>>1);
printf("bitwise complement=%d\n",~x);
return 0;
}
Output:
bitwise and=0
bitwise or=62
bitwise xor=62
bitwise leftshift=84
bitwise rightshift=21
bitwise complement=-43

#include <stdio.h>
int main()
{
int m = 40,n = 80,AND_opr,OR_opr,XOR_opr,NOT_opr ;
AND_opr = (m&n);
OR_opr = (m|n);
NOT_opr = (~m);
XOR_opr = (m^n);
printf("AND_opr value = %d\n",AND_opr );
printf("OR_opr value = %d\n",OR_opr );
printf("NOT_opr value = %d\n",NOT_opr );
printf("XOR_opr value = %d\n",XOR_opr );
printf("left_shift value = %d\n", m << 1);
printf("right_shift value = %d\n", m >> 1);
}

Output:

AND_opr value = 0
OR_opr value = 120
NOT_opr value = -41
XOR_opr value = 120
left_shift value = 80
right_shift value = 20

Conditional or ternary operators in C:

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 28


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


 Conditional operators return one value if condition is true and returns another value
is condition is false.
 This operator is also called as ternary operator.

Syntax : (Condition? true_value: false_value);


Example : (A > 100 ? 1 : 0);

In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if
else conditional statements.

Example program for conditional/ternary operators in C:

#include <stdio.h>
int main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf("x value is %d\n", x);
printf("y value is %d", y);
}

Output:

x value is 1
y value is 2

C – Increment/decrement Operators

 Increment operators are used to increase the value of the variable by one and
decrement operators are used to decrease the value of the variable by one in C
programs.

 Syntax:

Increment operator: ++var_name; (or) var_name++;


Decrement operator: – -var_name; (or) var_name – -;
 Syntax:
Increment operator : ++ i ; i ++ ;
Decrement operator : – – i ; i – – ;

Example program for increment operators in C:

 In this program, value of “i” is incremented one by one from 1 up to 9 using “i++”
operator and output is displayed as “1 2 3 4 5 6 7 8 9”.

//Example for increment operators

#include <stdio.h>

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 29


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


int main()
{
int i=1;
while(i<10)
{
printf("%d ",i);
i++;
}
}

Output:

123456789

Example program for decrement operators in C:

 In this program, value of “I” is decremented one by one from 20 up to 11 using “i–”
operator and output is displayed as “20 19 18 17 16 15 14 13 12 11”.

#include <stdio.h>
int main()
{
int i=20;
while(i>10)
{
printf("%d ",i);
i--;
}
}

Output:

20 19 18 17 16 15 14 13 12 11

Difference between pre/post increment & decrement operators in C:

 Below table will explain the difference between pre/post increment and decrement
operators in C.

S.no Operator type Operator Description


++i Value of i is incremented before assigning it to
1 Pre increment
variable i.
i++ Value of i is incremented after assigning it to variable
2 Post–increment
i.
— –i Value of i is decremented before assigning it to
3 Pre decrement
variable i.
4 Post_decrement i– — Value of i is decremented after assigning it to variable

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 30


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


i.

Example program for pre – increment operators in C:

//Example for increment operators


#include <stdio.h>
int main()
{
int i=0;
while(++i < 5 )
{
printf("%d ",i);
}
return 0;
}

Output:

1234

 Step 1 : In above program, value of “i” is incremented from 0 to 1 using pre-


increment operator.
 Step 2 : This incremented value “1” is compared with 5 in while expression.
 Step 3 : Then, this incremented value “1” is assigned to the variable “i”.
 Above 3 steps are continued until while expression becomes false and output is
displayed as “1 2 3 4”.

Example program for post – increment operators in C:

#include <stdio.h>
int main()
{
int i=0;
while(i++ < 5 )
{
printf("%d ",i);
}
return 0;
}

Output:

12345

 Step 1 : In this program, value of i “0” is compared with 5 in while expression.


 Step 2 : Then, value of “i” is incremented from 0 to 1 using post-increment operator.
 Step 3 : Then, this incremented value “1” is assigned to the variable “i”.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 31


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

 Above 3 steps are continued until while expression becomes false and output is
displayed as “1 2 3 4 5”.

Example program for pre – decrement operators in C:


#include <stdio.h>
int main()
{
int i=10;
while(--i > 5 )
{
printf("%d ",i);
}
return 0;
}

Output:

9876

 Step 1 : In above program, value of “i” is decremented from 10 to 9 using pre-


decrement operator.
 Step 2 : This decremented value “9” is compared with 5 in while expression.
 Step 3 : Then, this decremented value “9” is assigned to the variable “i”.
 Above 3 steps are continued until while expression becomes false and output is
displayed as “9 8 7 6”.

Example program for post – decrement operators in C:

#include <stdio.h>
int main()
{
int i=10;
while(i-- > 5 )
{
printf("%d ",i);
}
return 0;
}

Output:

98765

 Step 1 : In this program, value of i “10” is compared with 5 in while expression.


 Step 2 : Then, value of “i” is decremented from 10 to 9 using post-decrement
operator.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 32


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


 Step 3 : Then, this decremented value “9” is assigned to the variable “i”.
 Above 3 steps are continued until while expression becomes false and output is
displayed as “9 8 7 6 5”.

Special Operators in C:

S.no Operators Description


This is used to get the address of the variable.
1 &
Example : &a will give address of a.
This is used as pointer to a variable.
2 *
Example : * a where, * is pointer to the variable a.
This gives the size of the variable.
3 sizeof ()
Example : sizeof (char) will give us 1.

Example program for & and * operators in C:

 In this program, “&” symbol is used to get the address of the variable and “*”
symbol is used to get the value of the variable that the pointer is pointing to.

#include <stdio.h>
int main()
{
int *ptr, q;
q = 50;
/* address of q is assigned to ptr */
ptr = &q;
/* display q's value using ptr variable */
printf("%d", *ptr);
return 0;
}

Output:

50

Example program for sizeof() operator in C:

 sizeof() operator is used to find the memory space allocated for each C data types.

#include <stdio.h>
#include <limits.h>
int main()
{
int a;
char b;
float c;
double d;

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 33


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


printf("Storage size for int data type:%d \n",sizeof(a));
printf("Storage size for char data type:%d \n",sizeof(b));
printf("Storage size for float data type:%d \n",sizeof(c));
printf("Storage size for double data type:%d\n",sizeof(d));
return 0;
}

Output:

Storage size for int data type:4


Storage size for char data type:1
Storage size for float data type:4
Storage size for double data type:8

Operator Precedence in C

Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others; for example,
the multiplication operator has a higher precedence than the addition operator.

For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the
lowest appear at the bottom. Within an expression, higher precedence operators will be
evaluated first.

Category Operator Associativity


Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & sizeof Right to left
Multiplicative */% Left to right
Additive +- Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left
Comma , Left to right
Operator Precedence and Associativity in C
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 34
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Operator precedence determines which operator is performed first in an expression with
more than one operators with different precedence. For example 10 + 20 * 30 is calculated
as 10 + (20 * 30) and not as (10 + 20) * 30.

Associativity is used when two operators of same precedence appear in an expression.


Associativity can be either Left to Right or Right to Left. For example ‘*’ and ‘/’ have
same precedence and their associativity is Left to Right, so the expression “100 / 10 * 10″ is
treated as “(100 / 10) * 10″.

Precedence and Associativity are two characteristics of operators that determine the
evaluation order of subexpressions in absence of brackets.

1) Associativity is only used when there are two or more operators of same precedence.
The point to note is associativity doesn’t define the order in which operands of a single
operator are evaluated. For example consider the following program, associativity of the +
operator is left to right, but it doesn’t mean f1() is always called before f2(). The output of
following program is in-fact compiler dependent.

// Associativity is not used in the below program. Output


// is compiler dependent.
int x = 0;
int f1() {
x = 5;
return x;
}
int f2() {
x = 10;
return x;
}
int main() {
int p = f1() + f2();
printf("%d ", x);
return 0;
}

2) All operators with same precedence have same associativity


This is necessary, otherwise there won’t be any way for compiler to decide evaluation order
of expressions which have two operators of same precedence and different associativity. For
example + and – have same associativity.

3) Precedence and associativity of postfix ++ and prefix ++ are different


Precedence of postfix ++ is more than prefix ++, their associativity is also different.
Associativity of postfix ++ is left to right and associativity of prefix ++.

4) Comma has the least precedence among all operators and should be used carefully
For example consider the following program, the output is 1.

#include<stdio.h>
int main()
{
int a;
a = 1, 2, 3; // Evaluated as (a = 1), 2, 3
printf("%d", a);

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 35


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


return 0;
}

5) There is no chaining of comparison operators in C


In Python, expression like “c > b > a” is treated as “a > b and b > c”, but this type of
chaining doesn’t happen in C. For example consider the following program. The output of
following program is “FALSE”.

#include <stdio.h>
int main()
{
int a = 10, b = 20, c = 30;

// (c > b > a) is treated as ((c > b) > a), associativity of '>'


// is left to right. Therefore the value becomes ((30 > 20) > 10)
// which becomes (1 > 20)
if (c > b > a)
printf("TRUE");
else
printf("FALSE");
return 0;
}

Expression evaluation

In c language expression evaluation is mainly depends on priority and associativity.

Priority

This represents the evaluation of expression starts from "what" operator.

Associativity

It represents which operator should be evaluated first if an expression is containing more


than one operator with same priority.

Operator Priority Associativity


{}, (), [] 1 Left to right
++, --, ! 2 Right to left
*, /, % 3 Left to right
+, - 4 Left to right
<, <=, >, >=, ==, != 5 Left to right
&& 6 Left to right
|| 7 Left to right
?: 8 Right to left
=, +=, -=, *=, /=, %= 9 Right to left

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 36


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example 1:

Example 2:

C Type Conversion – Implicit & Explicit Type Conversion in C


When variables and constants of different types are combined in an expression then
they are converted to same data type. The process of converting one predefined type into
another is called type conversion.

Conversion between data types can be done in two ways by casting:

 Implicit casting
 Explicit casting

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 37


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Implicit casting

Implicit casting doesn't require a casting operator. This casting is normally used when
converting data from smaller integral types to larger or derived types to the base type.

int x = 123;
double y = x;

In the above statement, the conversion of data from int to double is done implicitly, in other
words programmer don't need to specify any type operators.

Explicit casting

Explicit casting requires a casting operator. This casting is normally used when converting a
double to int or a base type to a derived type.

double y = 123;
int x = (int)y;

In the above statement, we have to specify the type operator ( int) when converting from
double to int else the compiler will throw an error.

Conversion operators

Conversion operators help to cast user-defined types from one to the other much like the
basic types. For implicit or explicit conversion, we have to create a static method in the
corresponding class with method name as the type it returns including the keyword that says
implicit or explicit.

The usual arithmetic conversions are not performed for the assignment operators, nor for the
logical operators && and ||.

#include <stdio.h>
main() {
int i = 17;
char c = 'c'; /* ascii value is 99 */
float sum;
sum = i + c;
printf("Value of sum : %f\n", sum );
}

When the above code is compiled and executed, it produces the following result –
Value of sum : 116.000000

Control Statements

Decision Making and Branching

Condition: A condition is an expression built with relational operators along with logical
operators.
(a >= b) condition using relational operators

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 38


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


((a >= b) && a >= c)) condition using relational operators and logical operators

Every condition gives only one result that is either true or false (Boolean).

If statement: if is a conditional executable statement, which allows the user to express


conditions.

It has 4 forms…

 simple if
 if…else
 nested if
 else if ladder

Simple if: In case of simple if, a condition is tested, if the condition is true then the
statement followed by “if” will be executed.

Flowchart:

Syntax: if(condition) Eg: if (salary < 5000)


Statement-part; salary = salary + 500;
next-statement; printf(“\nSalary = %f”, salary);

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 39


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example:

#include <stdio.h>
int main()
{
int m=40,n=40;
if (m == n)
printf("m and n are equal");
}

Output:

m and n are equal

if else statement: Using “if else” a condition is tested, if the condition is true then the
statement next to “if” will be executed.
If the condition is false then the statement statement after “else” will be executed.
Any one of the statement parts will be executed but not both.

Flowchart:

Syntax: If(condition) Eg: if (salary < 5000)


Statement-1; bonus = 500;
else else
Statement-2; bonus = 700;
printf(“\nBonus = %d”);
next-statement;

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 40


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example:

#include <stdio.h>
int main()
{
int age;
int m=40,n=20;
if (m == n)
printf("m and n are equal");
else
printf("m and n are not equal");
}

Output:

m and n are not equal

nested if.. else statement: If an “if .. else” statement is enclosed within another “if”
statement, then it is called nested if .. else statement.

Syntax: if(condition-1) Eg: if (salary < 5000)


statement-1; bonus = 300;
else else
if (condition-2) if(salary > 5000)
statement-2; bonus = 700;
else else
statement-3; bonus = 500;
Example:

#include <stdio.h>
int main()
{
int m=40,n=20;
if (m>n)
printf("m is greater than n");
else
if(m<n)
printf("m is less than n");
else
printf("m is equal to n");
}

Output:

m is greater than n

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 41


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Flowchart:

else…if ladder: A sequence of conditions are tested followed by a sequence of statements


are to be executed to form an else…if ladder.

Syntax: if(condition-1) Eg: if (salary < 5000)


statement-1; bonus = 700;
else if (condition-2) else if(salary == 5000)
statement-2; bonus = 500;
else else
statement-3; bonus = 300;
Flowchart:
next-statement; printf(“\nBonus = %d”, bonus);

Example:

#include <stdio.h>
int main()
{
int m=40,n=20;
if (m>n)
printf("m is greater than n");
else if(m<n)
Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 42
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


printf("m is less than n");
else
printf("m is equal to n");
}

Output:

m is greater than n

switch statement: switch is a conditional branching statement. Using switch an expression


is tested. Based on the result value of the expression, a specific block of statements will be
executed.

Syntax: Switch(expression) Ex: Switch(n)


{ {
case 1: statement-1; case 1: printf(“One”);
break; break;
case 2: statement-2; case 2: printf(“Two”);
break; break;
. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . .
case n: statement-n; case 9: printf(“Nine”);
break; break;
default: default-statement; default: printf(“Try Again”);
break; break;
} }

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 43


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example:

#include <stdio.h>
int main()
{
int choice;
printf("Select any option number from 1 to 4 : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("You have selected first option");
break;
case 2:
printf("You have selected second option");
break;

case 3:
printf("You have selected third option");
break;

case 4:
printf("You have selected fourth option");
break;

default:
printf("Invalid option selected");
break;

}
return 0;
}

Menu
1. addition
2. subtraction
3. multiplication
4. quotient division
5. remainder division

Decision Making and Looping:

Loop: A loop can be defined as a repetition of statements some given number of times.
Loops can be divided into 2 types.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 44


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


 conditional loops
 unconditional loops

In case of unconditional loops, the programmer does not know how many times the loop is
to be repeated.
In case of conditional loops, the programmer knows how many times the loop is to be
repeated.

The 3 types of conditional loops are: while loop, do…while loop, and for loop.

while loop(entry control structure) : while is a conditional repetitive control structure. It


is an entry control structure. The statements present in the loop will be repeated until the
condition is true.
If the condition is not satisfied the the statements are not executed atleast once.

Syntax: while (condition) Ex: n = 1;


{ while (n<=10)
Statement part; {
} printf(“\n n = %d”, n);
next statement; n = n + 1;
}

Example:

Void main()
{
int count=1;
while (count <=5)
{
printf("%d ", count);
count++;
}
}

Output:

1 2 3 4 5

do…while loop (exit control structure) : do…while is a conditional repetitive control


structure. It is an exit control structure. The statement in the loop will be repeated as long
as the condition is true.
Though the condition is not satisfied the statements in the loop will be executed once.

Syntax: Ex:
do n=1;
{ do
Prepared by Dr. V.Neelima, Associate
Statement part; Professor, CSE Dept { Page 45
} while(condition); printf(“\n n = %d”, n);
} while(n<=10);
next statement;
JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example:

Void main()
{
int count=1;
do
{
printf("%d ", count);
count++;
} while (count <=5);
}

Output:

1 2 3 4 5

for loop: for is a conditional repetitive control structure. It is an entry control structure.
The statement in the loop will be repeated until the condition remains true. The for loop
includes initialization, test expression, increment / decrement statements into a single
structure.

Syntax: Ex: int i;


for(initialization;test-expression;increment/decrement) for(i=1;i<=10;i++)
{ {
Statement-part; printf(“\n %d”,i);
} }
next-statement

Example:

Void main()
{
int count;
for(count=0;count<=5,count++)
printf("%d", count);
}

Output:

1 2 3 4 5

Unconditional looping (Branching)


goto Statement: goto in C language is an unconditional branching statement. The control
flow is transferred from one place to other place in the program with out any specific
condition given.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 46


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


The goto requires a ‘label’ in order to identify the place where the the control is to be
transferred. A ‘label’ is any valid variable name, and must be followed by a colon.

Forward Loop Backward Loop

Syntax: goto label; Ex: goto JITS; Syntax: label: Ex: JITS:
Example: printf(“Hello”);
......... ......... statement;
int .main()
........ ......... ......... .........
{ label: JITS: ......... .........
int age;
statement; printf(“Hello”); goto label; goto JITS;

Vote:
printf("you are eligible for voting");

NoVote:
printf("you are not eligible to vote");

printf("Enter you age:");


scanf("%d", &age);
if(age>=18)
goto Vote;
else
goto NoVote;

return 0;
}

continue

The continue statement in ‘C’ programming forces the next iteration of the loop to take
place, by skipping any code in between.

For the for loop, continue statement causes the conditional test and increment portions of the
loop to execute. For the while and do...while loops, continue statement causes the program
control to pass to the conditional tests.

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 47


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21

Example: continue statement inside “for” loop


Void main()
{
int i;
for (int i=0; i<=10; i++)
{
if (i==5)
{
continue;
}
printf("%d ", i);
}
}

Output:

0 1 2 3 4 6 7 8 9 10

Example: continue statement inside “While” loop


Void main()
{
int i=0;
while(i<=10)
{
if (i==5)
{
continue;
}
printf("%d ", i);
i++;

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 48


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


}
}

Output:

0 1 2 3 4 6 7 8 9 10

Example: continue statement inside “do-while” loop


Void main()
{
int i=0;
do
{
if (i==5)
{
continue;
}
printf("%d ", i);
i++;
} while(i<=10);
}

Output:

0 1 2 3 4 6 7 8 9 10

#include <stdio.h>

int main () {

/* local variable definition */


int a = 10;

/* do loop execution */
do {

if( a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 49


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


printf("value of a: %d\n", a);
a++;

} while( a < 20 );

return 0;
}

Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16

Break:
The break statement in C programming has the following two usages −

 When a break statement is encountered inside a loop, the loop is immediately


terminated and the program control resumes at the next statement following the
loop.

 It can be used to terminate a case in the switch statement (covered in the next
chapter).

In nested loops, the break statement will stop the execution of the innermost loop and start
executing the next line of code after the block.

Syntax:
The syntax for a break statement in C is as follows −

break;

Flow Diagram:

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 50


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


Example:

#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 )
{
printf("value of a: %d\n", a);
a++;
if( a > 15)
{
/* terminate the loop using break statement */
break;
}
}
return 0;
}

When the above code is compiled and executed, it produces the following result −

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15

C Programming Comma Operator


#include<stdio.h>
void main() {
int num1 = 1, num2 = 2;
int res;
res = (num1, num2);
printf("%d", res);
}

Explanation :

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 51


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


1. Comma Operator has Lowest Precedence i.e it is having lowest priority so it is
evaluated at last.
2. Comma operator returns the value of the rightmost operand when multiple comma
operators are used inside an expression.
3. Comma Operator Can acts as –
o Operator : In the Expression
o Separator : Declaring Variable , In Function Call Parameter List

Comma as Separator:
int num1 = 1, num2 = 2;

It can acts as Separator in –

1. Function calls

2. Function definitions

3. Variable declarations

4. Enum declarations

Comma as Operator:
res = (num1, num2);

In this case value of rightmost operator will be assigned to the variable. In this case value of
num2 will be assigned to variable res.
Examples of comma operator:
Comma Operator have lowest priority in C Programming Operators. All possible operations
that can be performed on comma operator are summarized below –

Using Comma Operator along with Assignment


#include<stdio.h>
int main()
{
int i;
i = 1,2,3;
printf("i:%d\n",i);
return 0;
}

Output :

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 52


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


i:1

Explanation :

i = 1,2,3;

1. Above Expression contain 2 comma operator and 1 assignment operator.

2. If we check precedence table then we can say that “Comma” operator has lowest

precedence than assignment operator

3. So Assignment statement will be executed first .

4. 1 is assigned to variable “i”.

Using Comma Operator inside printf statement

#include<stdio.h>
#include< conio.h>
void main()
{
clrscr();
printf("Computer","Programming");
getch();
}

Output :

Computer

You might feel that answer of this statement should be “Programming” because comma operator
always returns rightmost operator, in case of printf statement once comma is read then it will
consider preceding things as variable or values for format specifier.

Using Comma Operator inside Switch case.


#include<stdio.h>
#include< conio.h>
void main()
{
int choice = 2 ;
switch(choice)
{
case 1,2,1:
printf("\nAllas");
break;

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 53


JYOTHISHMATHI INSTITUTE OF TECHNOLOGY AND SCIENCE
KARMNAGAR
(Approved by AICTE, New Delhi and- Affiliated
505481 to JNTU, Hyderabad)

I B.Tech I- Semester Programming for Problem Solving (R18) 2020-21


case 1,3,2:
printf("\nBabo");
break;
case 4,5,3:
printf("\nHurray");
break;
}
}

Output :

Babo

Using Comma Operator inside For Loop


#include<stdio.h>
int main()
{
int i,j;
for(i=0,j=0;i<5;i++)
{
printf("\nValue of J : %d",j);
j++;
}
return(0);
}

Output :

Value of J : 0
Value of J : 1
Value of J : 2
Value of J : 3
Value of J : 4

Prepared by Dr. V.Neelima, Associate Professor, CSE Dept Page 54

You might also like