Thanks to visit codestin.com
Credit goes to www.scribd.com

100% found this document useful (2 votes)
1K views19 pages

Pps - Unit-1 Bcs101 Notes

Uploaded by

dailybhaktifeed
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
100% found this document useful (2 votes)
1K views19 pages

Pps - Unit-1 Bcs101 Notes

Uploaded by

dailybhaktifeed
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/ 19

PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)

Lecture Notes (Unit-1)

Computer: A computer is a machine or device that performs processes, calculations and operations based on instructions
provided by a software or hardware program. It is designed to execute applications and provides a variety of solutions by
combining integrated hardware and software components.
A computer is made up of multiple parts and components that facilitate user functionality. A computer has two primary
categories:

 Hardware: Physical structure that houses a computer's processor, memory, storage, communication ports and
peripheral devices
 Software: Includes operating system (OS) and software applications

Digital Computer: All computer system (irrespective of their shape & size) performs the following 5 basic operations. It
converts the raw input data into information, which is useful to the users.

 Inputting: It is the process of entering data & instructions to the computer system.
 Storing: The data & instructions are stored for either initial or additional processing.
 Processing: It requires performing arithmetic or logical operation on the saved data to convert it into useful information.
 Outputting: It is the process of producing the output data to the end user.
 Controlling: The above operations have to be directed in a particular sequence to be completed.

Based on these 5 operations, we can sketch the block diagram of a computer.

Block Diagram of a Computer

 Input Unit: We need to first enter the data & instruction in the computer system, before any computation begins. This task
is accomplished by the input devices. (Eg: keyboard, mouse, scanner, digital camera etc.)
 Storage Unit: The data & instruction that are entered have to be stored in the computer. Similarly, the end results & the
intermediate results also have to be stored somewhere before being passed to the output unit. The storage unit provides
solution to all these issues. This storage unit is designed to save the initial data, the intermediate result & the final result.

Primary Storage: The primary storage, also called as the main memory, holds the data when the computer is currently on.
As soon as the system is switched off or restarted, the information held in primary storage disappears (i.e. it is volatile in
nature).
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Secondary Storage: The secondary storage, also called as the auxiliary storage, can retain information even when the
system is off. It is basically used for holding the program instructions & data on which the computer is not working on
currently, but needs to process them later.

 Central Processing Unit: Together the Control Unit & the Arithmetic Logic Unit are called as the Central Processing Unit
(CPU). The CPU is the brain of the computer. Like in humans, the major decisions are taken by the brain itself & other
body parts function as directed by the brain. Similarly in a computer system, all the major calculations & comparisons are
made inside the CPU. The CPU is responsible for activating & controlling the operation of other units of the computer
system.

Arithmetic Logic Unit: The actual execution of the instructions (arithmetic or logical operations) takes place over here.
Intermediate results that are generated in ALU are temporarily transferred back to the primary storage, until needed later.
Hence, data may move from the primary storage to ALU & back again to storage, many times, before the processing is
done.

Control Unit: This unit controls the operations of all parts of the computer but does not carry out any actual data
processing. It is responsible for the transfer of data and instructions among other units of the computer. It manages and
coordinates all the units of the system. It also communicates with Input/output devices for transfer of data or results from
the storage units.
 Output Unit: The job of an output unit is just the opposite of an input unit. It accepts the results produced by the computer
in coded form. It converts these coded results to human readable form. Finally, it displays the converted results to the
outside world with the help of output devices (E.g. monitors, printers, projectors etc).

Computer Memory– Memory is storage part in computer. It stores data, information, programs during processing in
computer. It stores data either temporarily or permanent basis. Memory used to important role in saving and retrieving
data.

Types of Memory– Mainly computer have two types memory

1. Primary Memory / Volatile Memory.


2. Secondary Memory / Non Volatile Memory.

1. Primary Memory / Volatile Memory– Primary memory is internal memory of the computer. It is also known as main
memory and Temporary memory. Primary Memory holds the data and instruction on which computer is currently working.
Primary Memory is nature volatile. It means when power is switched off it lost all data.
Types of Primary Memory– Primary memory is generally of two types.

 RAM (Random Access Memory) – It stands for Random Access Memory. RAM is known as read /writes memory. It
generally refereed as main memory of the computer system. It is a temporary memory. The information stored in this
memory is lost as the power supply to the computer is switched off. That’s why RAM is also called “Volatile Memory”.
RAM is also of two types:
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
a) Static RAM- Static RAM also known as SRAM, retain stored information as long as the power supply is ON. SRAM are
of higher coast and consume more power. They have higher speed than Dynamic RAM.
b) Dynamic RAM– Dynamic RAM also known as DRAM, its stored information in a very short time (a few milliseconds)
even though the power supply is ON. The Dynamic RAM is cheaper and moderate speed and also they consume less power.

 ROM (Read Only Memory) – It stands for Read Only Memory. ROM is a Permanent Type memory. Its content are not
lost when power supply is switched off. Content of ROM is decided by the computer manufacturer and permanently stored
at the time of manufacturing. ROM cannot be overwritten by the computer. It is also called “Non-Volatile Memory”.
ROM memory is three types names are following-

 PROM (Programmable Read Only Memory)-PROM chip is programmable ROM .It is PROM chips to write data once
and read many. Once chip has been programmed, the recorded information cannot be changed. PROM is also nonvolatile
memory.
 EPROM (Erasable Programmable Read Only Memory) - EPROM chip can be programmed time and again by erasing
the information stored earlier in it. Information stored in EPROM exposing the chip for some time ultraviolet light.
 EEPROM (Electrically Erasable Programmable Read Only Memory)-The EEPROM is programmed and erased by
special electrical waves in millisecond. A single byte of a data or the entire contents of device can be erased.

2. Secondary Memory / Non Volatile Memory– Secondary Memory is external memory of the computer. It is also
Known as Auxiliary memory and permanent memory. It is used to store the different programs and the information
permanently. Secondary Memory is nature non volatile. It means data is stored permanently even if power is switched
off.example: Floppy Disks, Magnetic (Hard) Disk, Magnetic Tapes, Pen Drive, Optical Disk (CD, DVD).
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Differences between Primary and Secondary Memory

S.N. Primary memory Secondary memory


1 Primary memory is temporary Secondary memory is permanent
Primary memory is directly accessible by
2 Secondary memory is not directly accessible by CPU
Processor/CPU
Nature of Parts of Primary memory varies. RAM-
3 It’s always Non-volatile in nature
volatile in nature. ROM- Non-volatile
Primary memory devices are more expensive than Secondary memory devices are less expensive when
4
secondary storage devices compare to primary memory devices
The memory devices used for primary memory are The secondary memory devices are magnetic and
5
semiconductor memories optical memories
Primary memory is also known as Main memory or Secondary memory is also known as External memory
6
Internal memory or Auxiliary memory
Examples: RAM, ROM, Cache memory, PROM, Examples: Hard Disk, Floppy Disk, Magnetic Tapes
7
EPROM, Registers etc etc

Cache Memory: A special very high-speed memory called a cache is sometimes used to increase the speed of
processing by making current program and data available to the CPU at a rapid rate.

The purpose of cache memory is to store program instructions and data that are used repeatedly in the operation of
programs or information that the CPU is likely to need next. The computer processor can access this information quickly
from the cache rather than having to get it from computer's main memory. In the Memory Hierarchy System, a cache
memory is placed between CPU & main memory.

Memory Hierarchy: The total memory capacity of a computer can be visualized by hierarchy of components. The
memory hierarchy system consists of all storage devices contained in a computer system from the slow Auxiliary Memory
to fast Main Memory and to smaller Cache memory.

A "memory hierarchy" in computer storage distinguishes each level in the “hierarchy" by response time. Each level
of the hierarchy is of higher speed and lower latency, and is of smaller size, than lower levels. ... Faster memory is
costly.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

So when we talk about a computer, we actually mean 2 things:


 Hardware- This hardware is responsible for all the physical work of the computer.
 Software- This software commands the hardware what to do & how to do it.Together, the hardware & software form the
computer system.This software is further classified as system software & application software.

System Software- System software are a set of programs, responsible for running the computer, controlling
various operations of computer systems and management of computer resources. They act as an interface between
the hardware of the computer & the application software. E.g.: Operating System

Application Software- Application software is a set of programs designed to solve a particular problem for users.
It allows the end user to do something besides simply running the hardware. E.g.: Web Browser, Gaming
Software, etc.

S.No. System Software Application Software

System software is used for operating Application software is used by user to perform
1. computer hardware. specific task.

System software are installed on the


computer when operating system is Application software are installed according to user’s
2. installed. requirements.

In general, the user does not interact with


system software because it works in the
3. background. In general, the user interacts with application software.

System software can run independently.


It provides platform for running Application software can’t run independently. They
4. application software. can’t run without the presence of system software.

Some examples of system software are


compiler, assembler, debugger, driver, Some examples of application software are word
5. etc. processor, web browser, media player, etc.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Translators: A program written in high-level language is called as source code. To convert the source code into
machine code, translators are needed. A translator takes a program written in source language as input and converts it into
a program in target language as output. It also detects and reports the error during translation.
Roles of translator:
1. Translating the high-level language program input into an equivalent machine language program.
2. Providing diagnostic messages wherever the programmer violates specification of the high-level language program.
Type of translators: The different types of translator are as follows:
 Compiler: Compiler is a translator which is used to convert programs in high-level language to low-level language. It
translates the entire program and also reports the errors in source program encountered during the translation.

 Interpreter: Interpreter is a translator which is used to convert programs in high-level language to low-level language.
Interpreter translates line by line and reports the error once it encountered during the translation process. It directly
executes the operations specified in the source program when the input is given by the user. It gives better error
diagnostics than a compiler.

 Assembler: Assembler is a translator which is used to translate the assembly language code into machine language.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Difference between Compiler and Interpreter:

BASIS FOR COMPILER INTERPRETER


COMPARISON
Input It takes an entire program at a time. It takes a single line of code or
instruction at a time.
Output It generates intermediate object code. It does not produce any intermediate
object code.
Working The compilation is done before Compilation and execution take place
mechanism execution. simultaneously.
Speed Comparatively faster Slower

Memory Memory requirement is more due to It requires less memory as it does not
the creation of object code. create intermediate object code.
Errors Display all errors after compilation, Displays error of each line one by one.
all at the same time.
Error detection Difficult Easier comparatively
Programming C, C++, C# uses compiler. PHP, Perl, Python, Ruby uses an
languages interpreter.

Loader: Loader is the program of the operating system which loads the executable from the disk into the primary
memory (RAM) for execution. It allocates the memory space to the executable module in main memory and then
transfers control to the beginning instruction of the program.
Linker: It is a computer program that takes one or more object files generated by a compiler and combines them into
one, executable program. Computer programs are usually made up of multiple modules that span separate object files, each
being a compiled computer program. The program as a whole refers to these separately compiled object files using
symbols. The linker combines these separate files into a single, unified program; resolving the symbolic references as it
goes along.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Computer Program: A program is a set of instructions following the rules of the chosen language.
Programming Language:
• A vocabulary and set of grammatical rules (syntax) for instructing a computer to perform specific tasks. • Programming
languages can be used to create computer programs.
• The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, FORTRAN,
Ada, and Pascal.

Generations of Programming Language:


So far Five Generations of programming languages have been defined. A brief introduction of each of the five generations
is given below

 First Generation Programming Language (1GL): First generation of programming language refers to machine
language.
 Machine language is lower level language which uses object code (sometimes also known as machine code). Object code
is the combination of binary digits.
 These languages directly talk to hardware.
 While easily understood by computers, machine languages are almost impossible for humans to use because they consist
entirely of numbers.
 Programs written in machine language are not portable.Example:

 Second Generation Programming Language (2GL): Second generation of languages is also low level language which
is known as assembly language.
 A program written in assembly language consists of a series of instructions mnemonics that correspond to a stream of
executable instructions, when translated by an assembler that can be loaded into memory and executed.
 Assembly languages use keywords and symbols (mnemonics) much like English, to form a programming language but at
the same time introduce a new problem.
 Programs written in machine language are not portable.
 The problem is that the computer doesn't understand the assembly code, so we need a way to convert it to machine code.
Assembly language programs are translated into machine language by a program called an assembler.

Example: Machine language: 10110000 01100001


Assembly language: mov a1, #061h
Meaning: Move the hexadecimal value 61 (97 decimal) into the processor register named "a1".
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
 Third Generation Programming Language (3GL):
 Third Generation programming languages are High level Programming languages. High-level languages allow us to write
computer code using instructions resembling everyday spoken language (for example: print, if, while) which are then
translated into machine language to be executed.
 Programs written in a high-level language need to be translated into machine language before they can be executed.
 Some programming languages use a compiler to perform this translation and others use an interpreter.
 The programmer spends less time developing software with a high level language than with assembly or machine
language because fewer instructions have to be created. Programs written in hidh level languages are portable.

Objectives of high-level languages:


 To relieve the programmer of the tedious task of writing programs in machine language and assembly languages.
 To provide programs that can be used on more than one type of machine with very few changes.
 To allow the programmer more time to focus on understanding the user’s needs and designing the software required
meeting those needs.
Examples of High-level Language: C,C++,JAVA,BASIC,COBOL, PASCAL,PHYTON

 Fourth Generation Programming Language (4GL):


General characteristics of 4GL are: a) Closer to human languages b) Portable c) Database supportive d) Simple and
requires less effort than 3GL e) Non procedural
Objectives of fourth generation languages:
1. Increasing the speed of developing programs and minimizing user effort to obtain information from computer.
2. Decreasing the skill level required of users so that they can concentrate on the application rather than coding, and thus
solves their own problems without the help of a professional programmer.
Different types of 4 GL are: a) Query Generator b) Report generator c) Form Generator

 Fifth Generation Programming Language (5GL):


 Natural Languages represent the next step in the development of programming languages; the text of a natural language
statement very closely resembles human speech.
 These languages are also designed to make the computer “smarter”. Languages used for writing programs for Artificial
Intelligence, Neural Network etc. come under 5GL.

Difference between Low-Level and High-Level languages:

High level languages Low level languages


1. It is programmer friendly language. It is a machine friendly language.
2. High level language is less memory Low level language is high memory efficient.
efficient.
3. It is easy to understand. It is tough to understand.
4. It is simple to debug It is complex to debug comparatively.
5. It is simple to maintain It is complex to maintain comparatively
6. It is portable. It is non-portable.
7. It can run on any platform. It is machine-dependent.
8. It needs compiler or interpreter for It needs assembler for translation.
translation
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Algorithm: An algorithm is a description of a procedure which terminates with a result. Algorithm is a step by-step
method of solving a problem. Purpose of algorithms is to implement re-usability in software applications. Once we have
designed the overview of solution to any problem in algorithmic form it can be coded in any language like C, C++, Java
etc.

Characteristics of algorithm are as follows:

 Finiteness: An algorithm terminates after a finite numbers of steps.


 Definiteness: Each step in algorithm is unambiguous means that the action specified by the
step cannot be interpreted (explain the meaning of) in multiple ways & can be performed without any confusion.
 Input: An algorithm accepts zero or more inputs.
 Output: An algorithm should produce at least one output.
 Effectiveness: It consists of basic instructions that are realizable. This means that the instructions can be performed by
using the given inputs in a finite amount of time.

Types of Algorithm:
Algorithms generally fall under two categories:

 Iterative: These algorithms sequentially execute the input using loops and conditional statements. E.g. Linear
search
 Recursive: These algorithms recursively break a larger problem into some smaller problems and solve those
problems. Then they combine the result of smaller problems to solve the main given problem.

Pseudo code is a simple way of writing programming code in English. Pseudo code is not actual programming language.
It uses short phrases to write code for programs before you actually create it in a specific language. Once you know what
the program is about and how it will function, then you can use pseudo code to create statements to achieve the required
results for your program. Algorithms are written in Pseudo code.

Example 1: Algorithm to compute the perimeter of a rectangle:

1. Start
2. Enter length, L
3. Enter width, B
4. Compute Perimeter = 2*L+ 2*B
5. Display Perimeter of a rectangle
6. End

Example 2: Algorithm to convert temperature Fahrenheit to Celsius


1. Start Step
2. Read Temperature in Fahrenheit F
3. C← 5/9*(F32)
4. Print Temperature in Celsius: C
5. End
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Flowchart: A flowchart is a graphical or pictorial representation of an algorithm. Each step in the process is
represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked
together with arrows showing the process flow direction. Some common flowchart symbols are listed below.

Symbol Name Description

This shape represents a process, action, or function.


Process symbol
It’s the most widely-used symbol in flowcharting.

This symbol represents the start points, end points,


Start/End symbol
and potential outcomes of a path.

Indicates a question to be answered — usually


yes/no or true/false. The flowchart path may then
Decision symbol
split off into different branches depending on the
answer or consequences thereafter.

This shape represents data that is available for input


Input/Output symbol or output as well as representing resources used or
generated.

↓ Control flow It represents the control flow inside flowchart.

Example 1: Flowchart to compute the perimeter of a Example 2: Flowchart to convert temperature Fahrenheit to
rectangle: Celsius
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Advantages of Flowchart:

 Better explanation of program: Flowchart is a pictorial description of any program. The program created by it can
easily be understood.

 Effective analysis: Through the flowcharts, the program is divided into smaller parts, making effective analysis of the
program.

 Designing of program: Using a flowchart, your program can be designed correctly.

 Systematic debugging: When any program is created, it is always tried to make it right, but still the mistake remains
somewhere. These mistakes can only be known when we start the execution of the program on the computer. The
mistake of this type of program, is called Bugs and the method of removing this mistake, is called Debugging. A flow
chart is very helpful in detecting, locating and removing the mistake in a program.

Disadvantages of Flowchart:

 Time consuming: Creating a flow chart takes more time. The flow chart is made especially for big complex problems.
Which take more time and very hard work?

 Difficult to make changes: If there is any modification in the flow chart the entire flowchart has to be recreated.

 No standard: Program flowcharts, although easy to understand, but cannot be written as a standard, like others language.
Nor with the help of flowcharts, it can be converted into the language of the program. Each programmer resolves the
problem in its own way and creates a flow chart accordingly.

Structure of C Program: The structure of a C program is a protocol (rules) to the programmer, which he has to
follow while writing a C program. The general basic structure of C program is shown in the figure below.

/* Documentation section */
/* Link section */
/* Definition section */
/* Global declaration section */
main()
{
Declaration part
Executable part (statements)
}
/* Sub-program section */

 The documentation section: is used for displaying any information about the program like the purpose of the program
etc, and this section should be enclosed within comment lines. The statements in the documentation section are ignored
by the compiler.
 The link section: consists of the inclusion of header files.
 The definition section: consists of macro definitions, defining constants etc. Anything declared in the global declaration
section is accessible throughout the program, i.e.accessible to all the functions in the program.
 main ( ): function is mandatory for any program and it includes two parts, the declaration part and the executable part.
 Sub-program section: is optional and used when we require including user defined functions in the program.

Based on this structure, we can sketch a C program.


PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Example:

/* This program accepts a number & displays it to the user*/

#include <stdio.h>
void main( )
{
int number;
printf("Please enter a number: " );
scanf("%d", &number );
printf("You entered %d", number );
return 0;
}
 #include
 The part of the compiler which actually gets your program from the source file is called the preprocessor.
#include <stdio.h>
 #include is a pre-processor directive. It is not really part of our program, but instead it is an instruction to the
compiler to make it do something. It tells the C compiler to include the contents of a file (in this case the system file
called stdio.h).
 The compiler knows it is a system file, and therefore must be looked for in a special place, by the fact that the
filename is enclosed in < > characters

 <stdio.h>
 stdio.h is the name of the standard library definition file for all STanDard Input and Output functions.
 Your program will almost certainly want to send information to the screen and read things from the keyboard, and
stdio.h is the name of the file in which the functions that we want to use are defined.
 The function we want to use is called printf. The actual code of printf will be tied in later by the linker.
 The ".h" portion of the filename is the language extension, which denotes an include file.

 void
This means that this means nothing. In this case, it is referring to the function whose name follows.
Void tells to C compiler that a given entity has no meaning, and produces no error.

 main
 In this particular example, the only function in the program is called main.
 A C program is typically made up of large number of functions. Each of these is given a name by the programmer
and they refer to each other as the program runs. C regards the name main as a special case and will run this
function first i.e. the program execution starts from main.

 { (Brace)
 As the name implies, braces come in packs of two - for every open brace there must be a matching close one.
Braces allow us to group pieces of program together, often called a block.
 A block can contain the declaration of variable used within it, followed by a sequence of program statements. In
this case the braces enclose the working parts of the function main.

 ; (semicolon)
 All statements in C programs are separated by ";" (semicolon) characters. It tells the compiler where a given statement
ends.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
 If the compiler does not find one of these characters where it expects to see one, then it will produce an error.

 scanf
 The function used to get input from the user during execution of program and stored in a variable of specified form is
called scanf ( ) function.

 printf
 This function is used to display text, constant or value of variable on screen in specified format.
 Just like scanf, it is described in the system file stdio.h.

Compilation & Execution of C Program

1. Source File- This file contains the source code of the program. The file extension of any c file is .c. The file contains C
source cod e that defines the main function & maybe other functions.
2. Header File- A header file is a file with extension .h which contains the C function declarations and macro definitions and to be
shared between several source files.

3. Object File- An object file is a file containing object code, with an extension .o, meaning relocatable format machine code that
is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as
input to the linker, which in turn typically generates an executable or library by combining parts of object files.
4. Executable File- The binary executable file is generated by the linker. The linker links the various object files to produce a
binary file that can be directly executed.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Types of Errors
 Syntax error: The errors which arises due to violation of any rule or regulation of C language during the development of
program those errors are known as Syntax error. These errors are these errors are identified by a compiler during compilation.
Example: missing of semicolon.

 Runtime error: The error that occurs during execution of program those errors are turn termed as runtime error. These errors
are identified during linking object code with system library. Example: incorrect header file name.

 Logical error: The errors which are introduced due to usage of wrong expression formula for logic in program these errors are
called as logical error for example using 2 * 3.14 as area of circle.

 Input data error: The error which occur during the data entry process because of entering wrong input values after the
execution of program

C Language Components

The four main components of C language are


1) The Character Set.
2) Tokens
3) Variables
4) Data Types

1) The Character Set: Character set is a set of valid characters that a language cab recognize. A character represents any letter,
digit or any other sign.

Types Character Set


Lower case a-z
Upper case A-Z
Digits 0-9
Special Character !@#$%^&*
White space Tab or new lines or space

2) Tokens: The smallest individual unit in a program is known as a token.C has five tokens:
i. Keywords
ii. Identifiers
iii. Constants
iv. Strings
v. Operators
vi. Special Symbols

i) Keywords: Keywords are reserved word in C. They have predefined meaning cannot changed. All keywords must be written in
lowercase. Eg:- auto,long,char,short etc.There are total 32 keywords in C.
ii) Identifiers: - Identifiers refer to the names of variable, functions and arrays. These are user- defined names. An identifier in C
can be made up of letters, digits and underscore. Identifiers may start with either alphabets or underscore. Two rules must be
kept in mind when naming identifiers.
iii) Constants: - Constants in C refers to fixed values that do not change during the execution of a program. C support several types
of constants.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)

Integer Constant: - An integer constant is a whole number without any fractional part. C has three types of integer
constants.

Decimal Constant: - Decimal integers consists of digits from 0 through 9


Eg.: 34,900,3457,-978

Octal Constant: - An Octal integer constant can be any combination of digits from 0 through 7. In C the first digit of an octal
number must be a zero(0) so as to differentiate it from a decimal number. Eg.: 06,034,-07564.

Hexadecimal Constant: Hexadecimal integer constants can be any combination of digits 0 through 9 and alphabets from „a‟
through „f‟ or „A‟ through „F‟. In C, a hexadecimal constant must begin with 0x or 0X (zero x) so as to differentiate it from
a decimal number. Eg:- 0x50,0XAC2 etc

Floating Constants (Real): Real or floating point numbers can contain both an integer part and a fractional part in the
number.
E.g:- 18.5, .18 etc.
Very large and very small numbers are represented using the exponent form. The exponent notation use the „E‟ or „e‟
symbol in the representation of the number. The number before E‟ is called as mantissa and the number after forms the
exponent.
Eg:-5.3E-5, 78e05

Single Character Constant: - A character constant in usually a single character or any symbol enclosed by single quotes.
Eg.: ch=’a’
String Constant: - A sequence of character enclosed between double quotes is called string constant. Eg. “Hello Good
Morning”
Punctuations: - 23 characters are used as punctuations in C. eg: + _ /; : > ! etc.
iv) String:- It may consist of any combination of digits, letters, escaped sequences and spaces enclosed in double quotes.Every
string constant ends up with a NULL character which is automatically assigned (before the closing double quotation mark) by
the compiler.
v) Operators: -
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C language is
rich in built-in operators and provides the following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Increment and decrement operators
• Conditional operators
vi) Special Symbols:!@#$%^&*
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
3) Variables: A variable is an object or element that may take on any value or a specified type. Variable are nothing but
identifiers, which are used to identify variables programming elements. Eg: name, sum, stu_name, acc_no etc.

4) Data types: Data types indicate the types of data a variable can have. A data types usually define a set of values, which
can be stored in the variable along with the operations that may be performed on those values. C includes two types of
data.

Primary or Primitive data type: These are fundamental data types in C.


Derived Data Types: Derived data types are constructed from the simple data types and or other derived data types.
Derived data include arrays, functions, pointers, references, constants, structures, unions and enumerations.

The data types in C can be classified as follows:


Type Storage size Value range

char 1 byte -128 to 127

unsigned char 1 byte 0 to 255

int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647

unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295

short 2 bytes -32,768 to 32,767

unsigned short 2 bytes 0 to 65,535

long 4 bytes -2,147,483,648 to 2,147,483,647

unsigned long 4 bytes 0 to 4,294,967,295

float 4 bytes 1.2E-38 to 3.4E+38 6 decimal places

double 8 bytes 2.3E-308 to 1.7E+308 15 decimal places

long double 10 bytes 3.4E-4932 to 1.1E+4932 19 decimal places


PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Input & Output Statements in C:

 The process of giving something to the computer is known as input. Input is mostly given through keyboard.
 The process of getting something from the computer is known as output.
Types of I/O Statements:

Type Input function Output function

Formatted I/O scanf() printf()

getchar(), getch(), puts() , putch(),


Unformatted I/O
gets(), getche() putchar()

 scanf() function: The function used to get input from the user during execution of program and stored in a variable of
specified form is called scanf() function.
Syntax:
scanf(“format string”,& variable name);
format string format specifier is written & address operator
Types:
Single input eg. scanf(“%d”,&a);
Multiple input eg. scanf(“%d %d”, &a,&b);|
Example :
#include<stdio.h>
void main ()
{
int a;
printf("Enter integer value:");
scanf("%d",&a);
printf("The value you enter = %d",a);
}
Output Enter integer value: 5 The value you enter =5

 printf () function: This function is used to display text, constant or value of variable on screen in specified format.
Syntax:
printf(“format string”, argument list);
Types:
printf(“hello world”); // Printf()with no argument list
printf(“the value of integar=%d”,a); //Printf() with one argument
printf(“Sum of %d+%d=%d”,a,b,a+b); //Printf()with more than one argument

 getchar(): The getchar function is a part of the standard C input/output library. It returns a single character from a standard
input device (typically a keyboard). The function does not require any arguments, though a pair of empty parentheses must
follow the word getchar.
Syntax
character variable = getchar( );
where character variable refers to some previously declared character variable
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
. getch() getche()

getch() is used to get a character getche() is used to get a character from console, and
from console but does not echo to echoes to the screen.
the screen.

It reads a single character directly getche() reads a single character from the keyboard and
from the keyboard, without echoing echoes it to the current text window, using direct video
to the screen. or BIOS.

 putchar():The putchar function like getchar is a part of the standard C input/output library. It transmits a single character
to the standard output device (the computer screen).
Syntax
putchar (character variable)
Where character variable refers to some previously declared character variable.

You might also like