What Is A Computer?: Software
What Is A Computer?: Software
Software
Program 1 Program 2
Computer language: it includes wide variety of languages used to communicate with the
computers. Computer languages can be divided into two types
Language
-1-
What is a Programming Language?
• It is an artificial language mainly used to control the behavior of a machine,
particularly a computer
• Programming languages are sub set of computer languages
Low level languages are further divided into Machine language and Assembly language
Low Level
Language
Machine Assembly
Language Language
Machine Language:
• This language is directly understood by the computer
• It doesn’t needs any translator
• Programs developed using M.L consists only 0’s and 1’s
• It is efficient for the computer and inefficient for the programmer
• It is difficult to debug programs written in this language
• The programmer has to know the details about hardware to write a program using
this language
Assembly Language:
• It is considered to be second generation language
• Unlike machine level language here we use come codes known as nmemonic
codes to develop a program
• But a translator program is required to translate assembly language to machine
language. This translator program is called “assembler”
Disadvantages:
• One of the major disadvantages is that assembly language is machine dependent.
A program written for one computer might not run in other computers with
different hardware configuration.
HIGH LEVEL LANGUAGES:
• Higher level languages are simple languages that use English and mathematical
symbols like +, -, %, / etc. for its program construction.
• Higher level languages are problem-oriented languages because the instructions
are suitable for solving a particular problem
• For EX: COBOL is suitable for business applications, FORTRAN is for scientific
purpose
• These are very easy to learn and use
-2-
Compiler:
? It is a computer program that translates one text written in computer
language to another computer language
? Original code is known as source code
? Output or target code is known as object code
Interpreter:
• It is a type of program translator used for translating higher level language into
machine language. It takes one statement of higher level languages, translate it
into machine language and immediately execute it.
• Translation and execution are carried out for each statement. It differs from
compiler, which translate the entire source program into machine code and does
involve in its execution.
• The advantage of interpreter compared to compiler is its fast response to changes
in source program.
• It eliminates the need for a separate compilation after changes to each program.
• Interpreters are easy to write and do not require large memory in computer.
• The disadvantage of interpreter is that it is time consuming method because each
time a statement in a program is executed then it is first translated.
• Thus compiled machine language program runs much faster than an interpreted
program.
System software: It is a computer software which manages and controls the hardware
Ex: Operating system
-3-
Programs
Flow Charts
-4-
Algorithms :
1. Accept two values from the user as the length and breadth of the rectangle.
2. Multiply the length and breadth to obtain the area.
3. Display the area.
By 1960 number of computer languages into existing almost each for a specific purpose.
At this stage people state to think why should be learn so many languages for each for
different purpose. Why not use only one language which can be programmed all possible
applications. An international committee were setup and they come with following.
Advantages:
-5-
2. c complier combines the capabilities of assemb ly language with the features of
high- level language, it is well suited for writing system software and commercial
applications.
3. Due to its variety of data types and powerful operators, programs written in c are
fast and efficient. C languages strength lies in built- in functions.
4. C programs written for one computer can be run in another with little or no
modification.
5. Major advantage of c language is its ability to support structured programming so
complex programs can be easily split into modules. This facilitates easier
debugging ,testing and maintenance.
6. Most important feature of c language is its ability to extend it self. Though c
program is a collection of functions supported by c library ,new functions can be
added to the library with ease.
7. ‘c’ having 32 key words
Documentation section
Link section
Definition section
Global declaration section
main()
{
Declaration Part
Executable Part
}
Subprogram section
FUNCTION 1
FUNCTION 2
Documentation Section:
Comments are used to enhance the programs readability. Comments may appear any
where in the program. They are placed within the delimiters /* and*/.while execution the
c compiler skips the lines that are marked as comment.
Link section:
The link section provides instructions to the compiler to link functions from the system
library.
-6-
Definition section:
C language allows you to assign names to constants. The constants with symbolic
constants.
Symbolic constants are used in the program for two purposes: To facilitate easier
modification, for better understanding.
#define pass_mark 60
#define pi 3.14159
The rules that are to be adhered to while using #define directive to define a symbolic
constant are as follows:
4. A blank space is required between the #define and the symbolic name and also
between symbolic name and constant
6. Symbolic name should not assigned another value within the program after
definition
8. #define statements can appear any where in the program but it should appear
before it is referenced in the program
There are some variables that are used in more than one function. Such variables are
called global variables and are declared in the global declaration section that is outside of
all the functions.
-7-
main() function section:
Every c program must have one main() function. This section contains two parts,
declaration part and executable part. The declaration part declares all the variables used
in the executable part. There is at least one statement in the executable part. These two
parts must appear between the opening and the closing braces. The program execution
begins at the opening brace and ends at the closing brace. The closing brace of the main
function section is the logical end of the program. All statements in the declaration and
executable parts end with a semicolon.
Subprogram section:
The subprograms section contains all the user-defined functions that are called in the
main function. User-defined functions are generally placed immediately after the main
function.
Executing a c program
1. Program creation
Program creation is done with the help of a text editor.
2. program compilation
During the program compilation process, the source code is translated into
a form is more suitable for execution. The translated code is known as
object code.
3. linking the program with c library functions
Linking the program is the process of putting together other program files
and functions that are required by the program for its execution. The
compiled and linked program is called the executable object code.
4. program execution
During the program execution, the executable object code is loaded into
the computer memory and the instructions are executed. During program
execution, data may be requested for input, which can be entered either
through keyboard or through a file
-8-
System Start
Syntax Yes
Errors
No Object Code
Correct Output
Stop
C
CHARACTERS
-9-
Complete character set
Letters
Digits
Uppercase A……..Z All decimal digits 0…..9
Lowercase a……..z
, comma & ampersand ! Exclamation ( left parenthesis
. Period ^ caret | vertical bar ) right
; semicolon * Asterisk / slash [ left bracket
: colon - Minus sign \ back slash ] right bracket
? Question mark + plus sign ~ tile symbol { left brace
‘ apostrophe < open angle _ under score } right brace
bracket
“ quotation mark > Close angle $ dollar sign
bracket
# number sign
White Spaces
Blank Spaces Carriage return Form Feed
Horizontal tab New Line
C –TOKENS
Smallest individual units of program are known as c tokens. C programs are written using
these tokens. C language has six types of tokens.
OPERATO
RS
SPECIAL KEYWOR
SYMBOLS DS
C
TOKENS
STRINGS CONSTAN
TS
IDENTIFIE
RS
- 10 -
Identifiers :
1. Names that are given to various elements of a program are called identifiers
2. Identifiers Consists of letters and digits, in any order
3. First character of an identifier must be a letter. Both lower and upper case letters
are permitted.
4. The underscore character, which is considered to be a letter, can be included
5. Some of the valid examples of an identifier are listed in the figure…
Eg:
y
calc-2
temp
volume
income_tax
Key words :
- 11 -
Constants
Fixed value in the program. C has 2 types of constants.
CONSTANTS
NUMERICAL CHARACTER
Valid Invalid
78 10.2, $455, 412589
1256
- 12 -
6) Range : 3.4 e -38 to 3.4 e +38
Valid : 3.25,555.1023
Invalid : 9.2.05
String may contain alphabets, digits, & specia l characters. String is also known as
alphanumeric
ASCII values not defined for strings whereas each character within the string has ASCII
value
These are special characters are used in output statements. each of them represents one
character, although they consists of two characters. These characters are known as escape
sequences.
Constant Meaning
\a Audio alert (bell)
\b Back space
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
- 13 -
\v Vertical tab
\’ Single quote
\” Double quote
\? Question mark
\\ Backslash
\0 Null
VARIABLE
VALID INVALID
Sum 2add
Product abc$
Digit break
A1b2c3 class strength
Reverse
Class_strength
Data type
Declaration
Variable Name
- 14 -
DATA TYPES
Data type specifies the properties of a variable like type of value that it can hold, memory
occupied by a variable
- 15 -
Qualifiers: using which we can modify the behavior of the data type
- 16 -
long double 80 3.4E-4932 to 3.4E+4932
INPUT/OUTPUT STATEMENTS
printf()
1. It is an output function
2. It is used to display message & values of variables
3. It is predefined in “stdio.h” ( header) file
4. It is call by value function
5. It deals with monitor
Syntax:
printf(“format specifier”, list of variables);
format specifier conatains Conversion characters like %d, %c, %f, %s and escape
characters like \n, \t, \b, \f
scanf()
1. It is an input function
2. It is used read some value into memory variables
3. It is predefined in “stdio.h” ( header) file
4. It is call by address function
5. It deals with keyboard
Syntax:
scanf(“format specifier”, list of addresses of variables);
Conversion characters like %d, %c, %f, %s and escape characters are ignored
Address of the variable is specified using the & (ampersand) symbol with name of the
variable
- 17 -
Data type Conversion
character
int %d or %i
unsigned long int %u
hexa decimal integer %x
octal integer %o
short int %h
long int %ld
long double %Ld
float %f
exponential %e
double precision %lf
char %c
string %s
C-IDE Environment
IDE stands for integrated development environment. It is one of the package was
designed by various companies. But now days in our locality all can use turbo company
C-IDE. Simply called as TC.
OPERATORS
An operator is a symbol that tells the computer to perform certain mathematical or logical
manipulations
1) Arithmetic operators
2) Relational operators
3) Logical operators
4) Assignment operators
5) Bitwise operators
6) Conditional operators
7) increment and decrement operators
8) Special operators
- 18 -
Arithmetic Operators:
Ex: + - * / %
1. All the above operators are binary operators. These can operate on any built –
in data type
2. Integer division truncates any fractional part. The modulo division produes the
remainder of an integer division
3. The modulo division operator % cannot be used on floating point data
Integer Arithmetic:
Real Arithmetic:
1. When one of the operands is real and other is integer the expression is called
mixed mode arithmetic expression.
2. Always the result of mixed mode arithmetic is of higher type
3. Ex: 9+3.6/2-1.5
Relational Operators
- 19 -
<= operand1 <= operand2
== operand1 == operand2
!= operand1 != operand2
Logical Operators
AND OR NOT
OR
- 20 -
0 1 1
1 0 1
1 1 1
NOT
Expression Outcome
1 0
0 1
Assignment operator:
V op= exp
Statement with simple Statement with
assignment operator shorthand operator
a=a+1 a+=1
a=a-1 a-=1
a=a*(n+1) a*=(n+1)
a=a/(n+1) a/=(n+1)
a=a%b a%=b
Conditional operator:
• “ ?: “ is ternary operator
• Conditional expression takes the following form
• Exp1 ? Exp2 : Exp3
• Exp1 is evaluated first. If it is true then the Exp2 is evaluated and its value
becomes the value of the exp ression.
• Note that only one of the expressions is e
- 21 -
• Post decrement – m– pre decrement - --m
• m++ and ++m mean the same thing when they form statements independently,
they behave differently when they are used in expressions on the right hand side
of an assignment statement.
• Expans ion for m++ or ++m is m = m+1
• Expansion for m-- or --m is m = m-1
Bitwise Operators:
Operator Meaning
| Bitwise OR
^ Bitwise exclusive OR
Special operators
- 22 -
operators will belong to any one of these levels. The operators that are in the
higher levels of precedence are evaluated first.
- 23 -
=,*=,/=,%=
Comma , Right to Left
Type Casting:
• Ex: int a = 9.5; here system truncates the decimal part of 9.5 and assigns only
integral part to integer variable ( TRUNCATION)
• float x=10; here system promotes value 10 to 10.0 (PROMOTION)
• char ch=65; here integer value 65 is converted into ‘A’
Explicit type casting : Here type casting is to be done by the programmer or user
- 24 -