You are on page 1of 11

Basic Computer Concepts

Computer
- is an electronic device that accepts data from the user, processes it,
produces results, displays them to the users, and stores the results for
future usage
Data
- is a collection of unorganized facts & figures and does not provide any
further information regarding patterns, context, etc. Hence data means
"unstructured facts and figures".
Information
- is a structured data i.e. organized meaningful and processed data. To
process the data and convert into information, a computer is used.
Functions of Computers
 Input
 Process
 Store
 Output
7 Characteristics of Computer System
1. Memory
2. Automation
3. Reliability
4. Versatility
5. Diligence
6. Accuracy
7. Speed
Basic Application of Computer
 Home
 Medical Field
 Entertainment
 Industry
 Education
 Government
 Banking
 Business
 Training
 Arts
 Science & Engineering

Components of Computer System


ALU
- All types of processing, such as comparisons, decision-making and
processing of non-numeric information takes place here
Control Unit
- This part of CPU extracts instructions, performs execution, maintains
and directs operations of entire system.
Memory Unit
- This is unit in which data and instructions given to computer as well as
results are stored.
Functions of Control Unit
 It controls all activities of computer
 Supervises flow of data within CPU
 Directs flow of data within CPU
 Transfers data to Arithmetic and Logic Unit
 Transfers results to memory
 Fetches results from memory to output devices
Computer Programming Languages
- Any of various languages for expressing a set of detailed instructions for
a digital computer
- Allow us to give instructions to a computer in a language the computer
understands
Language Type
 Machine and assembly languages
 Algorithmic languages (Fortran, Algol, C)
 Business Oriented Languages (Cobol, SQL)
 Object Oriented Languages ( C++, C#, Ada, Java, Visual Basic,
 Python)
 Declarative Languages (Prolog, Lisp)
 Scripting languages (PERL)
 Document Formatting Languages (Tex, PostScript, SGML)
 WWW Display Languages (HTML, XML)
 Web Scripting (Java Script)
History of C Programming Language
 C evolved from two previous languages, BCPL and B
 BCPL was developed in 1967 by Martin Richards
 Ken Thompson modeled many features in his B language
 In 1970 Ken Thompson used B to create early versions of the UNIX
operating system at Bell Laboratories
 The C language was evolved from B by Dennis Ritchie at Bell
 Laboratories and was originally implemented on a DEC PDP-11 computer
in 1972
 C uses many of the important concepts of BCPL and B while adding data
typing and other powerful features
 C is mostly hardware independent
 By the late 1970s, C had evolved into what is now referred to as
“traditional C.” The publication in 1978 of Kernighan and Ritchie’s book,
The C Programming Language, drew wide attention to the language. This
became one of the most successful computer science books of all time.
 The rapid expansion of C over various types of computers (sometimes
called hardware platforms) led to many variations that were similar but
often incompatible.
 In 1983, the X3J11 technical committee was created under the American
National Standards Committee on Computers and Information
Processing (X3) to “provide an unambiguous and machine independent
definition of the language.” In 1989, the standard was approved; this
standard was updated in 1999. The standards document is referred to as
INCITS/ISO/IEC 9899-1999

Program Development Life Cycle


1. Problem Definition
2. Problem Analysis
3. Algorithm Development
4. Coding & Documentation
5. Testing & Debugging
6. Maintenance
Algorithm
- The solution to any computing problem involves executing a series of
actions in a specific order. A procedure for solving a problem in terms of
1. The actions to be executed
2. The order in which these actions are to be executed
What makes a good algorithm?
1. Correctness
- Should always give the correct solution
2. Efficiency
- Should use minimum resources and should perform at an acceptable
speed
How do you measure efficiency?
Asymptotic Analysis
- Refers to defining the mathematical foundation/framing of its run-time
performance
Program Control
- Specifies the order in which statements are to be executed in a computer
program
Control Structure
- Control flow is the order in which individual statements, instructions or
function calls of an imperative program are executed or evaluated
1. Sequential
- default mode. Sequential execution of code statements (one line
after another)
2. Selection
- used for decisions, branching. Choosing between 2 or more
alternative paths.
3. Repetition
- used for looping, i.e. repeating a piece of code multiple times in a
row.
Pseudocode
- An artificial and informal language that helps you develop algorithm
- Similar to everyday English; it’s convenient and user friendly although
it’s not an actual computer programming language
Flowchart
- A graphical representation of an algorithm or of a portion of an
algorithm
- Drawn using certain special-purpose symbols such as rectangles,
diamonds, ovals, and small circles; these symbols are connected by
arrows called flowlines
Elements of C Program
1. Preprocessor directives (#)
- Preprocessor directives must be placed at the beginning of a file.
These directives perform different types of functions, but they are
commonly use to include a header files
 Header file - is a file with extension .
 h which contains C function declarations and macro definitions
to be shared
 between several source files.
 There are two types of header files: the files that the
programmer writes and the files that comes with your compiler.
2. Function
- A function is a self-contained block of code, other languages call them
procedure or subroutine. A function is just a series of statements
grouped together and given a name.
- main()
3. Statements
- Commands that the computer executes when the program runs. As a
general rule, all statements end with a semicolon(;), though there are
some exceptions to it.
4. Comments
 Comments are used to write some valuable notes while
programming. They also increase the readability of the program.
 2 Types of comments
- Single Line
- Multi Line

Constants
- an entity that doesn’t change
Variable
- An entity that may change
Types of C constants
a. Primary Constants
 Integer Constant
 Real Constant
- Often called Floating point constants
- Could be written in two forms
 Fractional form
 Exponential Form

Character Constant
- A character constant is a single alphabet, a single digit, or a
single special symbol enclosed within single inverted
commas
- Both inverted commas should point to the left
b. Secondary Constants
 Array
 Pointer
 Structure
 Union
 Enum, etc.

Rules for constructing Integer Constants


a. An integer constant must have at least one digit
b. It must not have a decimal point
c. It can be either positive or negative
d. If no sign precedes an integer, constant is assumed to be positive
e. No commas or blanks are allowed within an integer constant
f. The allowable range for integer constants is -32768 to 32767
Rules for constructing Real Constants (Exponential Form)
a. The mantissa part and the exponential part should be separated by a
letter e
b. The mantissa part may have a positive or negative sign
c. Default sign of mantissa part is positive
d. The exponent must have at least one digit, which must be a positive or
negative integer. Default sign is positive
e. Range of real constants expresses in exponential form is -3.4e38 to
3.4e38
Rules for constructing Real Constants (Fractional Form)
a. A real constant must have at least one digit
b. Must have decimal point
c. Could be either positive or negative
d. Default sign is positive
e. No commas or blanks are allowed within a real constant
Rules for constructing a Character Constant
a. Maximum length of character constant can be 1 character

Variable Declaration and Data Types


C Data Types
- A variable in C language must be given a type, which defines wat type of
data the variable will hold
 int – used to hold an integer
 char – can hold/store a character in it
 float – used to hold a float value
 double – a used to hold a double value
 void

Types of Variables in C
1. local variable
- declared inside the function or block
2. global variable
- declared outside the function or block. Any function can change
the value of global variable – it is available to all the functions
3. static variable
- declared with static keyword. It retains its value between multiple
function calls
4. automatic variable
- all variable in c that are declared inside the block are automatic
variable by default. We can explicitly declare an automatic variable
using auto keyword
5. external variable
- can share a variable in multiple C source files. To declare an
external variable, you need to use an external keyword
Rules in constructing C variable names
a. A variable name is any combination of 1 to 31 alphabets, digits, or
underscores. Some compilers allow variable names whose length could
be up to 247 characters. Still, it would be safer to stick to the rule of 31
characters.
b. First character in the variable name must be an alphabet or underscore
c. No commas or blanks are allowed within a variable name
d. No special symbol other than an underscore (as in gross_sal) can be used
in a variable name
Variable Declaration
- A statement in which a variable is stored by the compiler.
- <data type> <variable name>;
<data type> <variable name> = <variable initial value>;
Type Casting
- The different ways of changing an expression from one data type to
another.
Executable Statements
- Specify the actions to be performed during the execution of program
code.
- are normally executed in the sequence they appear in the program code.

C Arithmetic Expressions

C Arithmetic Expressions Notes:


 An arithmetic operation between an integer and integer always yields an
integer result.
 An operation between a real and real always yields a real result.
 An operation between an integer and real always yields a real result. In
this operation the integer is first promoted to a real and then the
operation is performed. Hence the result is real.
Types of Error
 Syntax Error
- also known as the compilation errors
- occurred at the compilation time, or we can say that the syntax
errors are thrown by the compilers
- mainly occurred due to the mistakes while typing or do not follow
the syntax of the specified programming language.
 Run-Time Error
- Sometimes the errors exist during the execution-time even after
the successful compilation known as run-time errors. When the
program is running, and it is not able to perform the operation is
the main cause of the run-time error.
 Linker Error
- mainly generated when the executable file of the program is not
created. This can be happened either due to the wrong function
prototyping or usage of the wrong header file.
 Logical Error
- leads to an undesired output. These errors produce the incorrect
output, but they are error-free
 Semantic Error
- occurred when the statements are not understandable by the
compiler
Compiler
- program that processes statements written in a particular programming
language and turns them into machine language or "code" that a
computer's processor uses
Conditions and Logical Expressions
3 logical operators in C

The and operator

The not operator

Precedence
- the NOT (!) operator has the highest precedence and it associates from
right to left. The precedence of AND (&&) operator is higher than OR (||)
operator and they both associates from left to right.

The if statement
- a non-zero value is considered to be true, whereas a zero is considered to
be false
- The group of statements after the if up to and not including the else is
called an ‘if block’. Similarly, the statements after the else form the ‘else
block’.
- Notice that the else is written exactly below the if. The statements in the
if block and those in the else block have been indented to the right. This
formatting convention is followed throughout the book to enable you to
understand the working of the program better.
- Had there been only one statement to be executed in the if block and
only one statement in the else block we could have dropped the pair of
braces.
- Had there been only one statement to be executed in the if block and
only one statement in the else block we could have dropped the pair of
braces.

You might also like