0% found this document useful (0 votes)
11 views

Computer Application II-biotech

Uploaded by

HARRY POTTER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Computer Application II-biotech

Uploaded by

HARRY POTTER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

1

COMPUTER
APPLICATIONS I & II

UNIT I:
COMPUTER ALGORITHMS AND
FUNDAMENTALS IN C
Computer Algorithms:
Basics of Algorithms- Pseudo code - Flowchart-Stack-Queues.
Fundamentals in C:
History of C- Basic Structure of a C program- Simple C Program- Character set - C tokens -
Keywords - Identifiers - Constants – Variables – Data Types -Declaration of Variable -
Assigning Values to Variables –Initialization.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


2

COMPUTER ALGORITHMS:
BASIC OF ALGORITHMS

The word Algorithm means “a process or set of rules to be followed in calculations or


other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that
step-by-step define how a work is to be executed upon in order to get the expected results.

It can be understood by taking an example of cooking a new recipe. To cook a new


recipe, one reads the instructions and steps and execute them one by one, in the given sequence.
The result thus obtained is the new dish cooked perfectly. Similarly, algorithms help to do a task
in programming to get the expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that can
be implemented in any language, and yet the output will be the same, as expected.

What are the Characteristics of an Algorithm?

 Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
 Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs.
 Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it
should be well-defined as well.
 Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite loops or
similar.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


3

Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon with
the available resources. It must not contain some future technology, or anything.
 Language Independent: The Algorithm designed must be language-independent, i.e. it must
be just plain instructions that can be implemented in any language, and yet the output will be
same, as expected.

Advantages of Algorithms:

 It is easy to understand.
 Algorithm is a step-wise representation of a solution to a given problem.
 In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for
the programmer to convert it into an actual program.

Disadvantages of Algorithms:

 Writing an algorithm takes a long time so it is time-consuming.


 Branching and Looping statements are difficult to show in Algorithms.

How to Design an Algorithm?

1. The problem that is to be solved by this algorithm.


2. The constraints of the problem that must be considered while solving the problem.
3. The input to be taken to solve the problem.
4. The output to be expected when the problem the is solved.
5. The solution to this problem, in the given constraints.
Then the algorithm is written with the help of above parameters such that it solves the
problem.
Example: Consider the example to add three numbers and print the sum.

 Step 1: Fulfilling the pre-requisites


As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled.
1. The problem that is to be solved by this algorithm: Add 3 numbers and print their sum.
2. The constraints of the problem that must be considered while solving the problem: The
numbers must contain only digits and no other characters.
3. The input to be taken to solve the problem: The three numbers to be added.
4. The output to be expected when the problem the is solved: The sum of the three numbers
taken as the input.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


4

5. The solution to this problem, in the given constraints: The solution consists of adding the
3 numbers. It can be done with the help of ‘+’ operator, or bit-wise, or any other
method.
 Step 2: Designing the algorithm
Now let’s design the algorithm with the help of above pre-requisites: Algorithm
to add 3 numbers and print their sum:
1. START
2. Declare 3 integer variables num1, num2 and num3.
3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3
respectively.
4. Declare an integer variable sum to store the resultant sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum.
6. Print the value of variable sum
7. END
 Step 3: Testing the algorithm by implementing it.
Inorder to test the algorithm, let’s implement it in C language.
1. Priori Analysis: “Priori” means “before”. Hence Priori analysis means checking the
algorithm before its implementation. In this, the algorithm is checked when it is written in
the form of theoretical steps. This Efficiency of an algorithm is measured by assuming that
all other factors, for example, processor speed, are constant and have no effect on the
implementation. This is done usually by the algorithm designer. It is in this method, that
the Algorithm Complexity is determined.
2. Posterior Analysis: “Posterior” means “after”. Hence Posterior analysis means checking
the algorithm after its implementation. In this, the algorithm is checked by implementing it in
any programming language and executing it. This analysis helps to get the actual and real
analysis report about correctness, space required, time consumed etc.
 Time Factor: Time is measured by counting the number of key operations such as
comparisons in the sorting algorithm.
 Space Factor: Space is measured by counting the maximum memory space required by the
algorithm.
1. Space Complexity: Space complexity of an algorithm refers to the amount of memory that
this algorithm requires to execute and get the result. This can be for inputs, temporary
operations, or outputs.
How to calculate Space Complexity?
The space complexity of an algorithm is calculated by determining following 2 components:
 Fixed Part: This refers to the space that is definitely required by the algorithm. For
example, input variables, output variables, program size, etc.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


5


Variable Part: This refers to the space that can be different based on the implementation
of the algorithm. For example, temporary variables, dynamic memory allocation,
recursion stack space, etc.
2. Time Complexity: Time complexity of an algorithm refers to the amount of time that this
algorithm requires to execute and get the result. This can be for normal operations,
conditional if-else statements, loop statements, etc.
How to calculate Time Complexity?
The time complexity of an algorithm is also calculated by determining following 2
components:
 Constant time part: Any instruction that is executed just once comes in this part. For
example, input, output, if-else, switch, etc.
 Variable Time Part: Any instruction that is executed more than once, say n times,
comes in this part. For example, loops, recursion, etc.

PSEUDO CODE

What is Pseudocode?

Pseudocode literally means ‘fake code’. It is an informal and contrived way of writing
programs in which you represent the sequence of actions and instructions (aka algorithms) in a
form that humans can easily understand.

You see, computers and human beings are quite different, and therein lies the problem.

The language of a computer is very rigid: you are not allowed to make any mistakes or
deviate from the rules. Even with the invention of high-level, human-readable languages like
JavaScript and Python, it’s still pretty hard for an average human developer to reason and
program in those coding languages.

With pseudocode, however, it’s the exact opposite. You make the rules. It doesn’t matter
what language you use to write your pseudocode. All that matters is comprehension.

In pseudocode, you don't have to think about semi-colons, curly braces, the syntax for
arrow functions, how to define promises, DOM methods and other core language principles. You
just have to be able to explain what you're thinking and doing.

Benefits of Writing Pseudocode

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


6

When you're writing code in a programming language, you’ll have to battle with strict
syntax and rigid coding patterns. But you write pseudocode in a language or form with which
you're very familiar.

Since pseudocode is an informal method of program design, you don’t have to obey
any set-out rules. You make the rules yourself.
Pseudocode acts as the bridge between your brain and computer’s code executor. It allows
you to plan instructions which follow a logical pattern, without including all of the technical
details.

Pseudocode is a great way of getting started with software programming as a beginner.


You won’t have to overwhelm your brain with coding syntax.

In fact, many companies organize programming tests for their interviewees in


pseudocode. This is because the importance of problem solving supersedes the ability to ‘hack’
computer code.

You can get quality code from many platforms online, but you have to learn problem
solving and practice it a lot.

Planning computer algorithms with pseudocode makes you meticulous. It helps you
explain exactly what each line in a software program should do. This is possible because you are
in full control of everything, which is one of the great features of pseudocode.

Example of Pseudocode

Pseudocode is a very intuitive way to develop software programs. To illustrate this, I am


going to refer back to a very simple program I wrote in my last article:
When a user fills in a form and clicks the submit button, execute a ValidateEmail function. What
should the function do?

1. Derive an email regular expression (regex) to test the user's email address against.
2. Access the user's email from the DOM and store it in a variable. Find and use the right DOM
method for that task.
3. With the email value now accessed and stored, create a conditional statement:
If the email format doesn’t match the rule specified by the regex, access the element with
the myAlert id attribute and pass in the “Invalid Email” message for the user to see.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


7

Else, if the above condition isn’t true and the email address format actually matches with
the regex, check to see if the database already has such an email address. If it already does,
access the element with the myAlert id attribute and pass in the “Email exists!” message for the
user to see.
Now, if both of these conditions aren’t met, (that is the email format matches the regex and
the database doesn’t have such an email address stored yet), push the users email address
into the database and pass in the “Successful!” message for the user to see.

How to Solve Programming Problems with Pseudocode

Solving programming problems can be hard. Not only do you have the logical part to
reckon with, but also the technical (code forming) part as well. I recently uncovered a brilliant
and effective formula for solving tricky coding problems.

Here are the steps you can follow to solving programming problems with pseudocode:

Step 1: Understand what the function does


First, you need to understand that all a function does is (optionally) accept data as input,
work on the data little by little, and finally return an output. The body of the function is what
actually solves the problem and it does so line by line.

Step 2: Make sure you understand the question


Next, you need to read and understand the question properly. This is arguably the most important
step in the process.

If you fail to properly understand the question, you won’t be able to work through the
problem and figure out the possible steps to take. Once you identify the main problem to be
solved you'll be ready to tackle it.

Step 3: Break the problem down.


Now you need to break down the problem into smaller parts and sub-problems.
With each smaller problem you solve, you'll get closer to solving the main problem.

It helps to represent these problem solving steps in the clearest and most easily
understandable way you can – which is psedocode!

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


8

Start solving: open and use tools like Google, Stack Overflow, MDN, and of course
freeCodeCamp! :)
For every step of the problem that you solve, test the output to make sure you’re on the right
path. Keep solving these small problems until you arrive at the final solution.

FLOWCHART
WHAT IS A FLOWCHART?

Also called: process flowchart, process flow diagram

Variations: macro flowchart, top-down flowchart, detailed flowchart (also called process
map, micro map, service map, or symbolic flowchart), deployment flowchart (also called down-
across or cross-functional flowchart), several-leveled flowchart

A flowchart is a picture of the separate steps of a process in sequential order. It is a


generic tool that can be adapted for a wide variety of purposes, and can be used to describe
various processes, such as a manufacturing process, an administrative or service process, or a
project plan. It's a common process analysis tool and one of the seven basic quality tools.

Elements that may be included in a flowchart are a sequence of actions, materials or services
entering or leaving the process (inputs and outputs), decisions that must be made, people who
become involved, time involved at each step, and/or process measurements.

History

Flowcharts to document business processes came into use in the 1920s and ‘30s. In
1921, industrial engineers Frank and Lillian Gilbreth introduced the “Flow Process Chart”
to the American Society of Mechanical Engineers (ASME). In the early 1930s, industrial
engineer Allan H. Morgensen used Gilbreth’s tools to present conferences on making work more
efficient to business people at his company. In the 1940s, two Morgensen students, Art
Spinanger and Ben S. Graham, spread the methods more widely. Spinanger introduced the work
simplification methods to Procter and Gamble. Graham, a director at Standard Register
Industrial, adapted flow process charts to information processing. In 1947, ASME adopted a
symbol system for Flow Process Charts, derived from the Gilbreths’ original work.

Also in the late ‘40s, Herman Goldstine and John Van Neumann used flowcharts to
develop computer programs, and diagramming soon became increasingly popular for computer
programs and algorithms of all kinds. Flowcharts are still used for programming today,
although pseudocode, a combination of words and coding language

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


9

meant for human reading, is often used to depict deeper levels of detail and get closer to a
final product.

In Japan, Kaoru Ishikawa (1915-1989), a key figure in quality initiatives in


manufacturing, named flowcharts as one of the key tools of quality control, along with
complementary tools such as the Histogram, Check Sheet and Cause-and-Effect Diagram, now
often called the Ishikawa Diagram.

WHEN TO USE A FLOWCHART

 To develop understanding of how a process is done


 To study a process for improvement
 To communicate to others how a process is done
 When better communication is needed between people involved with the same process
 To document a process
 When planning a project

FLOWCHART BASIC PROCEDURE

Materials needed: Sticky notes or cards, a large piece of flipchart paper or newsprint, and
marking pens.

1. Define the process to be diagrammed. Write its title at the top of the work surface.
2. Discuss and decide on the boundaries of your process: Where or when does the process start?
Where or when does it end? Discuss and decide on the level of detail to be included in the
diagram.
3. Brainstorm the activities that take place. Write each on a card or sticky note.
4. Arrange the activities in proper sequence.
5. When all activities are included and everyone agrees that the sequence is correct, draw arrows
to show the flow of the process.
6. Review the flowchart with others involved in the process (workers, supervisors, suppliers,
customers) to see if they agree that the process is drawn accurately.

Flowchart Considerations

 Don’t worry about drawing the flowchart the "right way." Ultimately, the right way is the
way that helps those involved understand the process.
 Identify and involve in the flowcharting process all key people involved with the process. This
includes suppliers, customers, and supervisors. Involve them in the actual

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


10

flowcharting sessions by interviewing them before the sessions and/or by showing them the
developing flowchart between work sessions and obtaining their feedback.
 Do not assign a "technical expert" to draw the flowchart. People who actually perform the
process should do it.

Types of flowcharts

Different authors describe various types of flowcharts in different terms. These people include
published experts such as Alan B. Sterneckert, Andrew Veronis, Marilyn Bohl and Mark A.
Fryman.

Sterneckert, in his 2003 book Critical Incident Management, listed four popular flowchart types,
framed around the concept of flow controls rather than the flow itself:

Document Flowcharts: These “have the purpose of showing existing controls over
document-flow through the components of a system. … The chart is read from left to
right and documents the flow of documents through the various business units.”

Data Flowcharts: These show “the controls governing data flows in a system. … Data
flowcharts are used primarily to show the channels that data is transmitted through the
system rather than how controls flow.”

System Flowcharts: These “show the flow of data to and through the major components
of a system such as data entry, programs, storage media, processors, and communication
networks.”

Program Flowcharts: These show “the controls placed internally to a program within a
system.”

Veronis , in his 1978 book Microprocessors: Design and Applications, outlined three flowchart
types based on scope and level of detail:

System Flowchart: Identifies the devices to be used.

General Flowchart: Overview.

Detailed Flowchart: Increased detail.

Bohl, in her 1978 book A Guide for Programmers, listed only two:

System Flowchart.

Program Flowchart.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


11

But Fryman, in his 2001 book Quality and Process Improvement, differentiated the types in
multiple ways from more of a business perspective than a computer perspective:

Decision Flowchart.

Logic Flowchart.

Systems Flowchart.

Product Flowchart.

Process Flowchart.

Additional flowchart types defined by others include:

Swimlane Diagram, a.k.a Swimlane Flowchart: To delineate who does what in cross- team
processes.

Workflow Flowchart: To document workflows, often involving tasks, documents and


information in offices.

Event-Driven Process Chain (EPC) Flowchart: To document or plan a business process.

Specification and Description Language (SDL) Flowchart: To brainstorm computer


algorithms using three basic components: system definition, block and process.

How to plan and draw a basic flowchart

1. Define your purpose and scope. What do you hope to accomplish? Are you studying the right
things with appropriate start and end points to accomplish that purpose? Be detailed enough
in your research but simple enough in your charting to communicate with your intended
audience.

2. Identify the tasks in chronological order. This might involve talking to participants, observing
a process and/or reviewing any existing documentation. You might write out the steps in note
form, or begin a rough chart.

3. Organize them by type and corresponding shape, such as process, decision, data, inputs or
outputs.

4. Draw your chart, either sketching by hand or using a program such as Lucidchart.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


12

5. Confirm your flowchart, walking through the steps with people who participate in the process.
Observe the process to make sure you haven’t missed anything important to your
purpose.

STACK
Stack is a linear data structure that follows a particular order in which the operations are
performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Mainly the following three basic operations are performed in the stack:
Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow
condition.
Pop: Removes an item from the stack. The items are popped in the reversed order in which
they are pushed. If the stack is empty, then it is said to be an Underflow condition.
Peek or Top: Returns the top element of the stack.
isEmpty: Returns true if the stack is empty, else false.

How to understand a stack practically?

There are many real-life examples of a stack. Consider the simple example of plates
stacked over one another in a canteen. The plate which is at the top is the first one to be removed,
i.e. the plate which has been placed at the bottommost position remains in the stack for the
longest period of time. So, it can be simply seen to follow the LIFO/FILO order.

Time Complexities of operations on stack:

push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of these
operations.
Applications of stack:
Balancing of symbols
Infix to Postfix /Prefix conversion
Redo-undo features at many places like editors, photoshop.
Forward and backward feature in web browsers
Used in many algorithms like Tower of Hanoi, tree traversals, stock span problem,
histogram problem.
Backtracking is one of the algorithm designing techniques. Some examples of backtracking
are the Knight-Tour problem, N-Queen problem, find your way through a maze, and game-
like chess or checkers in all these problems we dive into someway if that way is not efficient
we come back to the previous state and go into some another

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


13

path. To get back from a current state we need to store the previous state for that purpose we
need a stack.
In Graph Algorithms like Topological Sorting and Strongly Connected Components
In Memory management, any modern computer uses a stack as the primary management for
a running purpose. Each program that is running in a computer system has its own memory
allocations
String reversal is also another application of stack. Here one by one each character gets
inserted into the stack. So the first character of the string is on the bottom of the stack and the
last element of a string is on the top of the stack. After Performing the pop operations on the
stack we get a string in reverse order.

Implementation:
There are two ways to implement a stack:
Using array
Using linked list

Stack in Python
A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First- In/Last-
Out (FILO) manner. In stack, a new element is added at one end and an element is removed from
that end only. The insert and delete operations are often called push and pop.

The functions associated with stack are:


empty() – Returns whether the stack is empty – Time Complexity: O(1)
size() – Returns the size of the stack – Time Complexity: O(1)
top() – Returns a reference to the topmost element of the stack – Time Complexity: O(1)
push(a) – Inserts the element ‘a’ at the top of the stack – Time Complexity: O(1)
pop() – Deletes the topmost element of the stack – Time Complexity: O(1)

Implementation

There are various ways from which a stack can be implemented in Python. This article
covers the implementation of a stack using data structures and modules from the Python library.
Stack in Python can be implemented using the following ways:
list
Collections.deque
queue.LifoQueue

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


14

Implementation using list:

Python’s built-in data structure list can be used as a stack. Instead of push(), append() is
used to add elements to the top of the stack while pop() removes the element in LIFO order.
Unfortunately, the list has a few shortcomings. The biggest issue is that it can run into
speed issues as it grows. The items in the list are stored next to each other in memory, if the
stack grows bigger than the block of memory that currently holds it, then Python needs to do
some memory allocations. This can lead to some append() calls taking much longer than other
ones.

Implementation using collections.deque:

Python stack can be implemented using the deque class from the collections module.
Deque is preferred over the list in the cases where we need quicker append and pop operations
from both the ends of the container, as deque provides an O(1) time complexity for append and
pop operations as compared to list which provides O( n) time complexity.
The same methods on deque as seen in the list are used, append() and pop().

Implementation using queue module

Queue module also has a LIFO Queue, which is basically a Stack. Data is inserted into
Queue using the put() function and get() takes data out from the Queue.
There are various functions available in this module:
maxsize – Number of items allowed in the queue.
empty() – Return True if the queue is empty, False otherwise.
full() – Return True if there are maxsize items in the queue. If the queue was initialized
with maxsize=0 (the default), then full() never returns True.
get() – Remove and return an item from the queue. If the queue is empty, wait until an item
is available.
get_nowait() – Return an item if one is immediately available, else raise QueueEmpty.
put(item) – Put an item into the queue. If the queue is full, wait until a free slot is available
before adding the item.
put_nowait(item) – Put an item into the queue without blocking.
qsize() – Return the number of items in the queue. If no free slot is immediately available,
raise QueueFull.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


15

QUEUE
Like Stack, Queue is a linear structure which follows a particular order in which the
operations are performed. The order is First In First Out (FIFO). A good example of queue is any
queue of consumers for a resource where the consumer that came first is served first.

The difference between stacks and queues is in removing. In a stack we remove the
item the most recently added; in a queue, we remove the item the least recently added.

Operations on Queue:

Mainly the following four basic operations are performed on queue: Enqueue:
Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.
Dequeue: Removes an item from the queue. The items are popped in the same order in which
they are pushed. If the queue is empty, then it is said to be an Underflow condition. Front: Get
the front item from queue.
Rear: Get the last item from queue.

Applications of Queue:

Queue is used when things don’t have to be processed immediately, but have to be
processed in First In First Out order like Breadth First Search. This property of Queue
makes it also useful in following kind of scenarios.
1) When a resource is shared among multiple consumers. Examples include CPU scheduling,
Disk Scheduling.
2) When data is transferred asynchronously (data not necessarily received at same rate as sent)
between two processes. Examples include IO Buffers, pipes, file IO, etc. See this for
more detailed applications of Queue and Stack.

Array implementation Of Queue

For implementing queue, we need to keep track of two indices, front and rear. We
enqueue an item at the rear and dequeue an item from the front. If we simply increment front and
rear indices, then there may be problems, the front may reach the end of the array. The solution
to this problem is to increase front and rear in circular manner.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


16

Queue in Python
Like stack, queue is a linear data structure that stores items in First In First Out (FIFO)
manner. With a queue the least recently added item is removed first. A good example of queue is
any queue of consumers for a resource where the consumer that came first is served first.

Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an Overflow
condition – Time Complexity : O(1)
Dequeue: Removes an item from the queue. The items are popped in the same order in
which they are pushed. If the queue is empty, then it is said to be an Underflow condition –
Time Complexity : O(1)
Front: Get the front item from queue – Time Complexity : O(1)
Rear: Get the last item from queue – Time Complexity : O(1)

Implementation

There are various ways to implement a queue in Python. This article covers the
implementation of queue using data structures and modules from Python library. Queue in
Python can be implemented by the following ways:

list
collections.deque
queue.Queue

Implementation using list


List is a Python’s built-in data structure that can be used as a queue. Instead of enqueue()
and dequeue(), append() and pop() function is used. However, lists are quite slow for this
purpose because inserting or deleting an element at the beginning requires shifting all of the
other elements by one, requiring O(n) time.

Priority Queue
Priority Queue is an abstract data type, which is similar to a queue, however, in the
priority queue, every element has some priority. The priority of the elements in a priority queue
determines the order in which elements are removed from the priority queue. Therefore all the
elements are either arranged in an ascending or descending order.
So, a priority Queue is an extension of the queue with the following properties.
Every item has a priority associated with it.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


17

An element with high priority is dequeued before an element with low priority.
If two elements have the same priority, they are served according to their order in the queue.
In the below priority queue, an element with a maximum ASCII value will have the highest
priority. The elements with higher priority are served first.

A typical priority queue supports the following operations:

1) Insertion: When a new element is inserted in a priority queue, it moves to the empty slot
from top to bottom and left to right. However, if the element is not in the correct place then it
will be compared with the parent node. If the element is not in the correct order, the elements are
swapped. The swapping process continues until all the elements are placed in the correct
position.
2) Deletion: As you know that in a max heap, the maximum element is the root node. And it
will remove the element which has maximum priority first. Thus, you remove the root node from
the queue. This removal creates an empty slot, which will be further filled with new insertion.
Then, it compares the newly inserted element with all the elements inside the queue to maintain
the heap invariant.
3) Peek: This operation helps to return the maximum element from Max Heap or minimum
element from Min Heap without deleting the node from the priority queue.

Types of Priority Queue:

1) Ascending Order: As the name suggests, in ascending order priority queue, the element
with a lower priority value is given a higher priority in the priority list. For example, if we have
the following elements in a priority queue arranged in ascending order like 4,6,8,9,10. Here, 4
is the smallest number, therefore, it will get the highest priority in a priority queue.
2) Descending order: The root node is the maximum element in a max heap, as you may know.
It will also remove the element with the highest priority first. As a result, the root node is
removed from the queue. This deletion leaves an empty space, which will be filled with fresh
insertions in the future. The heap invariant is then maintained by comparing the newly inserted
element to all other entries in the queue.

How to Implement Priority Queue?


Priority queue can be implemented using the following data structures:
Arrays
Linked list

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


18

Heap data structure


Binary search tree

HISTORY OF C

There are many programming languages in use today, one of which is C. There are many
offshoots of the C programming language, including Objective-C, C++, and C#. None of these
are the same language. So, how did C begin?

The Beginning

The C programming language came out of Bell Labs in the early 1970s. According to the
Bell Labs paper The Development of the C Language by Dennis Ritchie, “The C programming
language was devised in the early 1970s as a system implementation language for the nascent
Unix operating system. Derived from the typeless language BCPL, it evolved a type structure;
created on a tiny machine as a tool to improve a meager programming environment.” Originally,
Ken Thompson, a Bell Labs employee, desired to make a programming language for the new
Unix platform. Thompson modified the BCPL system language and created B. However, not
many utilities were ever written in B due to its slow nature and inability to take advantage of
PDP-11 features in the operating system. This led to Ritchie improving on B, and thus creating
C.

Early Implementations and Language Standard

The development of C was to become the basis for Unix. According to the Bell Labs
paper, “By early 1973, the essentials of modern C were complete. The language and compiler
were strong enough to permit us to rewrite the Unix kernel for the PDP-11 in C during the
summer of the year.” This now meant that C was becoming a strong language that could, and
would be, implemented across many systems. By the middle of the 1970s, the C-based Unix was
used in many projects within the Bell System as well as “a small group of research-oriented
industrial, academic, and government organizations outside [Bell Labs]".

In 1978, Brian Kernighan and Dennis Ritchie published The C Programming Language,
which would serve as the language reference until a formal standard was adopted. Five years
later, the American National Standard Institute (ANSI) formed the committee, X3J11, to
establish the formal standard of C. The C standard was ratified as ANSI X3.159-1989
“Programming Language C”. This was the first formal standard of C.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


19

Currently, we are on the fourth standard of C, known as C18 as it was published in June of 2018
JavaTpoint.

Uses Today

According to Toptal, UNIX operating systems are written in C and most of Linux is also
in C. Also databases such as Oracle Database, MySQL, MS SQL Server, and PostgresSQL are at
least partially written in C. C is the basis of many system kernels. Other programming languages,
like Python and Perl, use compilers or interpreters that are written in C.

C has changed over the years and is still a common language to use in lower level
programs, like kernels. But it is also used for many applications ranging from device drivers to
other programming languages’ compilers or interpreters. The language also made way for
C++, Objective-C, C#, and many more C-based languages that each have their own speciality.

BASIC STRUCTURE OF A C PROGRAM

The components of the basic structure of a C program consists of 7 parts

1. Document section
2. Preprocessor/link Section
3. Definition section
4. Global declaration section
5. Function declaration section
6. Main function
7. User-defined function section
1. Documentation Section

It is the section in which you can give comments to make the program more
interactive. The compiler won’t compile this and hence this portion would not be displyed
on the output screen.

2. Preprocessor directives Section

This section involves the use of header files that are to included necessarily program.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


20

3. Definition section

This section involves the variable definition and declaration in C.

4. Global declaration Section

This section is used to define the global variables to be used in the programs, that
means you can use these variables throughout the program.

5. Function prototype declaration section

This section gives the information about a function that includes, the data type or the
return type, the parameters passed or the arguments.

6. Main function

It is the major section from where the execution of the program begins. The main
section involves the declaration and executable section.

7. User-defined function section

When you want to define your function that fulfills a particular requirement, you can
define them in this section.

SIMPLE C PROGRAM

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}

Output

Hello, World!

How "Hello, World!" program works?

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


21

The #include is a preprocessor command that tells the compiler to include the contents (standard input
of stdio.h and output) file in the program.
The stdio.h file contains functions such as scanf() and printf() to take input and display
output respectively.
If you use the printf() function without writing #include <stdio.h>, the program will not
compile.
The execution of a C program starts from the main() function.
printf() is a library function to send formatted output to the screen. In this
program, printf() displays Hello, World! text on the screen.
The return 0; statement is the "Exit status" of the program. In simple terms, the
program ends with this statement.

CHARACTER SET

In the C programming language, the character set refers to a set of all the valid characters
that we can use in the source program for forming words, expressions, and numbers.
The source character set contains all the characters that we want to use for the source
program text. On the other hand, the execution character set consists of the set of those
characters that we might use during the execution of any program. Thus, it is not a prerequisite
that the execution character set and the source character set will be the same, or they will match
altogether.

Use of Character Set in C

Just like we use a set of various words, numbers, statements, etc., in any language for
communication, the C programming language also consists of a set of various different types of
characters. These are known as the characters in C. They include digits, alphabets, special
symbols, etc. The C language provides support for about 256 characters.
Every program that we draft for the C program consists of various statements. We use
words for constructing these statements. Meanwhile, we use characters for constructing these
statements. These characters must be from the C language character set. Let us look at the set of
characters offered by the C language.

Types of Characters in C

The C programming language provides support for the following types of characters. In other
words, these are the valid characters that we can use in the C language:

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


22

 Digits
 Alphabets
 Main Characters
All of these serve a different set of purposes, and we use them in different contexts in the C
language.

Alphabets
The C programming language provides support for all the alphabets that we use in the
English language. Thus, in simpler words, a C program would easily support a total of 52
different characters- 26 uppercase and 26 lowercase.

Digits
The C programming language provides the support for all the digits that help in
constructing/ supporting the numeric values or expressions in a program. These range from 0 to
9, and also help in defining an identifier. Thus, the C language supports a total of 10 digits for
constructing the numeric values or expressions in any program

Special Characters
We use some special characters in the C language for some special purposes, such as
logical operations, mathematical operations, checking of conditions, backspaces, white spaces,
etc.
We can also use these characters for defining the identifiers in a much better way.
For instance, we use underscores for constructing a longer name for a variable, etc.

White Spaces

The white spaces in the C programming language contain the following:

 Blank Spaces
 Carriage Return
 Tab
 New Line

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


23

C TOKENS

Tokens in C is the most important element to be used in creating a program in C. We can


define the token as the smallest individual element in C. For `example, we cannot create a
sentence without using words; similarly, we cannot create a program in C without using tokens
in C. Therefore, we can say that tokens in C is the building block or the basic component for
creating a program in C language.

Classification of tokens in C

Tokens in C language can be divided into the following categories:

o Keywords in C
o Identifiers in C
o Strings in C
o Operators in C
o Constant in C
o Special Characters in C

Keywords

Keywords in C can be defined as the pre-defined or the reserved words having its own
importance, and each keyword has its own functionality. Since keywords are the pre- defined
words used by the compiler, so they cannot be used as the variable names. If the keywords are
used as the variable names, it means that we are assigning a different meaning to the keyword,
which is not allowed.

Identifiers in C

Identifiers in C are used for naming variables, functions, arrays, structures, etc. Identifiers
in C are the user-defined words. It can be composed of uppercase letters, lowercase letters,
underscore, or digits, but the starting letter should be either an underscore or an alphabet.
Identifiers cannot be used as keywords. Rules for constructing identifiers in C are given below:

o The first character of an identifier should be either an alphabet or an underscore, and then
it can be followed by any of the character, digit, or underscore.
o It should not begin with any numerical digit.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


24

o In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say
that identifiers are case sensitive.
o Commas or blank spaces cannot be specified within an identifier.
o Keywords cannot be represented as an identifier.
o The length of the identifiers should not be more than 31 characters.
o Identifiers should be written in such a way that it is meaningful, short, and easy to read.

Strings in C

Strings in C are always represented as an array of characters having null character '\0' at
the end of the string. This null character denotes the end of the string. Strings in C are enclosed
within double quotes, while characters are enclosed within single characters. The size of a string
is a number of characters that the string contains.

Now, we describe the strings in different ways:

char a[10] = "javatpoint"; // The compiler allocates the 10 bytes to the 'a' array. char

a[] = "javatpoint"; // The compiler allocates the memory at the run time.

char a[10] = {'j','a','v','a','t','p','o','i','n','t','\0'}; // String is represented in the form of characters.

Operators in C

Operators in C is a special symbol used to perform the functions. The data items on which the
operators are applied are known as operands. Operators are applied between the operands.
Depending on the number of operands, operators are classified as follows:

Unary Operator

A unary operator is an operator applied to the single operand. For example: increment operator
(++), decrement operator (--), sizeof, (type)*.

Binary Operator

The binary operator is an operator applied between two operands. The following is the list of the
binary operators:

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


25

o Arithmetic Operators
o Relational Operators
o Shift Operators
o Logical Operators
o Bitwise Operators
o Conditional Operators
o Assignment Operator
o Misc Operator

Constants in C

A constant is a value assigned to the variable which will remain the same throughout the
program, i.e., the constant value cannot be changed.

There are two ways of declaring constant:

o Using const keyword


o Using #define pre-processor

Special characters in C

Some special characters are used in C, and they have a special meaning which cannot be used
for another purpose.

o Square brackets [ ]: The opening and closing brackets represent the single and
multidimensional subscripts.
o Simple brackets ( ): It is used in function declaration and function calling. For example,
printf() is a pre-defined function.
o Curly braces { }: It is used in the opening and closing of the code. It is used in the
opening and closing of the loops.
o Comma (,): It is used for separating for more than one statement and for example,
separating function parameters in a function call, separating the variable when printing
the value of more than one variable using a single printf statement.
o Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we
are using the header file.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


26

o Asterisk (*): This symbol is used to represent pointers and also used as an operator for
multiplication.
o Tilde (~): It is used as a destructor to free memory.
o Period (.): It is used to access a member of a structure or a union.

KEYWORDS

A keyword is a reserved word. You cannot use it as a variable name, constant name, etc.
There are only 32 reserved words (keywords) in the C language.

Here is a list of all keywords allowed in ANSI C.

C Keywords
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned

IDENTIFIERS

C identifiers represent the name in the C program, for example, variables, functions,
arrays, structures, unions, labels, etc. An identifier can be composed of letters such as uppercase,
lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an
underscore. If the identifier is not used in the external linkage, then it is called as an internal
identifier. If the identifier is used in the external linkage, then it is called as an external identifier.

We can say that an identifier is a collection of alphanumeric characters that begins either
with an alphabetical character or an underscore, which are used to represent various
programming elements such as variables, functions, arrays, structures, unions, labels, etc. There
are 52 alphabetical characters (uppercase and lowercase), underscore character, and

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


27

ten numerical digits (0-9) that represent the identifiers. There is a total of 63 alphanumerical
characters that represent the identifiers.

Rules for constructing C identifiers

o The first character of an identifier should be either an alphabet or an underscore, and then
it can be followed by any of the character, digit, or underscore.
o It should not begin with any numerical digit.
o In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say
that identifiers are case sensitive.
o Commas or blank spaces cannot be specified within an identifier.
o Keywords cannot be represented as an identifier.
o The length of the identifiers should not be more than 31 characters.
o Identifiers should be written in such a way that it is meaningful, short, and easy to read.

Types of identifiers

o Internal identifier
o External identifier

Internal Identifier

If the identifier is not used in the external linkage, then it is known as an internal identifier. The
internal identifiers can be local variables.

External Identifier

If the identifier is used in the external linkage, then it is known as an external identifier. The
external identifiers can be function names, global variables.

CONSTANTS

A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a',
3.4, "c programming" etc.

There are different types of constants in C programming.

List of Constants in C

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


28

Constant Example

Decimal Constant 10, 20, 450 etc.

Real or Floating-point Constant 10.3, 20.2, 450.6 etc.

Octal Constant 021, 033, 046 etc.

Hexadecimal Constant 0x2a, 0x7b, 0xaa etc.

Character Constant 'a', 'b', 'x' etc.

String Constant "c", "c program", "c in javatpoint" etc.

Constant is a value that cannot be changed during program execution; it is fixed.

In C language, a number or character or string of characters is called a constant. And it can be


any data type. Constants are also called as literals.

There are two types of constants −

Primary constants − Integer, float, and character are called as Primary constants.

Secondary constants − Array, structures, pointers, Enum, etc., called as secondary


constants.

ways to define constant in C

There are two ways to define constant in C programming.

1. const keyword
2. #define preprocessor

C const keyword

The const keyword is used to define constant in C programming. C

#define preprocessor

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


29

The #define preprocessor is also used to define constant. We will learn about #define
preprocessor directive later.

VARIABLES

A variable is a name of the memory location. It is used to store data. Its value can be changed,
and it can be reused many times.

It is a way to represent memory location through symbol so that it can be easily identified. Let's

see the syntax to declare a variable:

type variable_list;

The example of declaring the variable is given below:


1. int a;
2. float b;
3. char c;

Here, a, b, c are variables. The int, float, char are the data types.

We can also provide values while declaring the variables as given below:

4. int a=10,b=20;//declaring 2 variable of integer type


5. float f=20.8;
6. char c='A';

Rules for defining variables

o A variable can have alphabets, digits, and underscore.


o A variable name can start with the alphabet, and underscore only. It can't start with a
digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:

1. int a;
2. int _ab;
3. int a30;

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


30

Invalid variable names:

1. int 2;
2. int a b;
3. int long;

Types of Variables in C

There are many types of variables in c:

1. local variable
2. global variable
3. static variable
4. automatic variable
5. external variable

Local Variable

A variable that is declared inside the function or block is called a local variable. It

must be declared at the start of the block.

void function1(){
int x=10;//local variable
}

You must have to initialize the local variable before it is used

Global Variable

A variable that is declared outside the function or block is called a global variable. Any
function can change the value of the global variable. It is available to all the functions.

It must be declared at the start of the block.

int value=20;//global variable


void function1(){
int x=10;//local variable

Static Variable

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


31

A variable that is declared with the static keyword is called static variable. It

retains its value between multiple function calls.

void function1(){
int x=10;//local variable
tatic int y=10;//static variable
x=x+1;
y=y+1;
printf("%d,%d",x,y);
}

If you call this function many times, the local variable will print the same value for each function
call, e.g, 11,11,11 and so on. But the static variable will print the incremented value in each
function call, e.g. 11, 12, 13 and so on.

Automatic Variable

All variables in C that are declared inside the block, are automatic variables by default. We can
explicitly declare an automatic variable using auto keyword.

void main(){
int x=10;//local variable (also automatic)
auto int y=20;//automatic variable
}

External Variable

We can share a variable in multiple C source files by using an external variable. To declare an
external variable, you need to use extern keyword.

=extern int x=10;//external variable (also global)


#include "myfile.h"
#include <stdio.h>
void printValue(){
printf("Global variable: %d", global_variable);

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


32

DATA TYPES
Each variable in C has an associated data type. Each data type requires different amounts of
memory and has some specific operations which can be performed over it. Let us briefly describe
them one by one:
Following are the examples of some very common data types used in C:
 char: The most basic data type in C. It stores a single character and requires a single byte of
memory in almost all compilers.
 int: As the name suggests, an int variable is used to store an integer.
 float: It is used to store decimal numbers (numbers with floating point value) with single
precision.
 double: It is used to store decimal numbers (numbers with floating point value) with double
precision.

There are the following data types in C language.

Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type enum

Void Data Type void

Basic Data Types

The basic data types are integer-based and floating-point based. C language supports both signed
and unsigned literals.

The memory size of the basic data types may change according to 32 or 64-bit operating system.

Let's see the basic data types. Its size is given according to 32-bit architecture.

Data Types Memory Size Range

char 1 byte −128 to 127

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


33

signed char 1 byte −128 to 127

unsigned char 1 byte 0 to 255

short 2 byte −32,768 to 32,767

signed short 2 byte −32,768 to 32,767

unsigned short 2 byte 0 to 65,535

int 2 byte −32,768 to 32,767

signed int 2 byte −32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte −32,768 to 32,767

signed short int 2 byte −32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

float 4 byte

double 8 byte

long double 10 byte

The types in C can be classified as follows −

Sr.No. Types & Description

1
Basic Types

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


34

They are arithmetic types and are further classified into: (a) integer types and (b)
floating-point types.

2 Enumerated types
They are again arithmetic types and they are used to define variables that can
only assign certain discrete integer values throughout the program.

3 The type void


The type specifier void indicates that no value is available.

4
Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union
types and (e) Function types.

The void Type

The void type specifies that no value is available. It is used in three kinds of situations −

Sr.No. Types & Description

1 Function returns as void


There are various functions in C which do not return any value or you can say
they return void. A function with no return value has the return type as void. For
example, void exit (int status);

2 Function arguments as void


There are various functions in C which do not accept any parameter. A function
with no parameter can accept a void. For example, int rand(void);

3
Pointers to void

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


35

A pointer of type void * represents the address of an object, but not its type. For
example, a memory allocation function void *malloc( size_t size
); returns a pointer to void which can be casted to any data type.

DECLARATION OF VARIABLE

A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in C has a specific type, which determines the size and layout of the
variable's memory; the range of values that can be stored within that memory; and the set of
operations that can be applied to the variable.
The name of a variable can be composed of letters, digits, and the underscore character.
It must begin with either a letter or an underscore. Upper and lowercase letters are distinct
because C is case-sensitive. Based on the basic types explained in the previous chapter, there
will be the following basic variable types −

Sr.No. Type & Description

1 char
Typically a single octet(one byte). It is an integer type.

2 int
The most natural size of integer for the machine.

3 float
A single-precision floating point value.

4 double
A double-precision floating point value.

5 void
Represents the absence of type.

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


36

C programming language also allows to define various other types of variables, which we will
cover in subsequent chapters like Enumeration, Pointer, Array, Structure, Union, etc. For this
chapter, let us study only basic variable types.

Variable Definition in C

A variable definition tells the compiler where and how much storage to create for the variable.
A variable definition specifies a data type and contains a list of one or more variables of that
type as follows −
type variable_list;
Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any
user-defined object; and variable_list may consist of one or more identifier names separated by
commas. Some valid declarations are shown here −
int i, j, k;
char c, ch;
float f, salary;
double d;

The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to
create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer
consists of an equal sign followed by a constant expression as follows −
type variable_name = value;
Some examples are −
extern int d = 3, f = 5; // declaration of d and f.
int d = 3, f = 5; // definition and initializing d and f.
byte z = 22; // definition and initializes z.
char x = 'x'; // the variable x has the value 'x'.
For definition without an initializer: variables with static storage duration are implicitly
initialized with NULL (all bytes have the value 0); the initial value of all other variables are
undefined.

Variable Declaration in C

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


37

A variable declaration provides assurance to the compiler that there exists a variable with the
given type and name so that the compiler can proceed for further compilation without requiring
the complete detail about the variable. A variable definition has its meaning at the time of
compilation only, the compiler needs actual variable definition at the time of linking the
program.
A variable declaration is useful when you are using multiple files and you define your variable
in one of the files which will be available at the time of linking of the program. You will use the
keyword extern to declare a variable at any place. Though you can declare a variable multiple
times in your C program, it can be defined only once in a file, a function, or a block of code.

Example

Try the following example, where variables have been declared at the top, but they have been
defined and initialized inside the main function −
#include <stdio.h>

// Variable declaration:
extern int a, b;
extern int c;
extern float f;

int main () {

/* variable definition: */
int a, b;
int c;
float f;

/* actual initialization */ a
= 10;
b = 20;

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

f = 70.0/3.0;
printf("value of f : %f \n", f);

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


38

return 0;
}
When the above code is compiled and executed, it produces the following result −
value of c : 30
value of f : 23.333334
The same concept applies on function declaration where you provide a function name at the
time of its declaration and its actual definition can be given anywhere else. For example −
// function declaration
int func();

int main() {

// function call
int i = func();
}

// function definition int


func() {
return 0;
}

Lvalues and Rvalues in C

There are two kinds of expressions in C −


 lvalue − Expressions that refer to a memory location are called "lvalue" expressions.
An lvalue may appear as either the left-hand or right-hand side of an assignment.
 rvalue − The term rvalue refers to a data value that is stored at some address in memory.
An rvalue is an expression that cannot have a value assigned to it which means an rvalue
may appear on the right-hand side but not on the left-hand side of an assignment.
Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric
literals are rvalues and so they may not be assigned and cannot appear on the left-hand side.
Take a look at the following valid and invalid statements −
int g = 20; // valid statement

10 = 20; // invalid statement; would generate compile-time error

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


39

ASSIGNING VALUES TO VARIABLES


Within an SPL routine, use the LET statement to assign values to the variables you have
already defined.

If you do not assign a value to a variable, either by an argument passed to the routine or
by a LET statement, the variable has an undefined value.

An undefined value is different from a NULL value. If you attempt to use a variable with
an undefined value within the SPL routine, you receive an error.

You can assign a value to a routine variable in any of the following ways:

 Use a LET statement.


 Use a SELECT INTO statement.
 Use a CALL statement with a procedure that has a RETURNING clause.
 Use an EXECUTE PROCEDURE INTO or EXECUTE FUNCTION INTO statement.

 The LET statement


 Other ways to assign values to variables

INITIALIZATION
In computer programming, initialization (or initialisation) is the assignment of an initial
value for a data object or variable. The manner in which initialization is performed depends on
programming language, as well as type, storage class, etc., of an object to be initialized.
Programming constructs which perform initialization are typically called initializers and
initializer lists. Initialization is distinct from (and preceded by) declaration, although the
two can sometimes be conflated in practice. The complement of initialization is finalization,
which is primarily used for objects, but not variables.
Initialization is done either by statically embedding the value at compile time, or else by
assignment at run time. A section of code that performs such initialization is generally known as
"initialization code" and may include other, one-time-only, functions such as opening files; in
object-oriented programming, initialization code may be part of a constructor (class method)
or an initializer (instance method). Setting a memory location to hexadecimal zeroes is also
sometimes known as "clearing" and is often performed by an exclusive or instruction (both
operands specifying the same variable), at machine code level, since it requires no additional
memory access.
Initializer

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


40

In C/C99/C++, an initializer is an optional part of a declarator. It consists of the '='


character followed by an expression or a comma-separated list of expressions placed in curly
brackets (braces). The latter list is sometimes called the "initializer list" or "initialization list"
(although the term "initializer list" is formally reserved for initialization of class/struct members
in C++; see below). A declaration which creates a data object, instead of merely describing its
existence, is commonly called a definition.
Many find it convenient to draw a distinction between the terms "declaration" and
"definition", as in the commonly seen phrase "the distinction between a
declaration and definition...", implying that a declaration merely designates a data object (or
function). In fact, according to the C++ standard, a definition is a declaration. Still, the usage
"declarations and definitions", although formally incorrect, is common. [1] Although all
definitions are declarations, not all declarations are definitions.
C examples:

int i = 0;
int k[4] = {0, 1};
char tx[3] = 'a';
char ty[2] = 'f';
struct Point {int x; int y;} p = { .y = 13, .x = 7 };

C++ examples:

int i2(0);
int j[2] = {rand(), k[0]};
MyClass* xox = new MyClass(0, "zaza");
point q = {0, i + 1};

Initializer list[edit]
In C++, a constructor of a class/struct can have an initializer list within the definition but prior to
the constructor body. It is important to note that when you use an initialization list, the values are
not assigned to the variable. They are initialized. In the below example, 0 is initialized into re
and im. Example:

struct IntComplex {
IntComplex() : re(0), im(0) {}

int re;
int im;

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


41

};

Here, the construct : re(0), im(0) is the initializer list.


Sometimes the term "initializer list" is also used to refer to the list of expressions in the array
or struct initializer.
C++11 provides for a more powerful concept of initializer lists, by means of a template, called
std::initializer_list.
Default initialization[edit]
Data initialization may occur without explicit syntax in a program to do so. For example, if
static variables are declared without an initializer, then those of primitive data types are
initialized with the value of zero of the corresponding type, while static objects of class type are
initialized with their default constructors.

---------------------------------------------END---------------------------------------

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


42

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


43

II BSc BT UNIT I – C & Py SNGC – NEETHU DS


44

II BSc BT UNIT I – C & Py SNGC – NEETHU DS

You might also like