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

Introduction to Basic Programming

The document provides an introduction to basic programming concepts, including variables, control flow statements, functions, arrays, and pointers, primarily using the C programming language. It also discusses computer software, its classifications, and the roles of various software components like compilers, interpreters, and linkers. Additionally, it outlines the structure of a C program and its key characteristics, emphasizing C's use in system programming.

Uploaded by

Mahak Garg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction to Basic Programming

The document provides an introduction to basic programming concepts, including variables, control flow statements, functions, arrays, and pointers, primarily using the C programming language. It also discusses computer software, its classifications, and the roles of various software components like compilers, interpreters, and linkers. Additionally, it outlines the structure of a C program and its key characteristics, emphasizing C's use in system programming.

Uploaded by

Mahak Garg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Introduction to Basic

Programming
Books
• The C Programming Language by Brian
Kernighan and Dennis Ritchie 2nd edition
• Absolute beginner's guide to C, Greg M. Perry,
Edition 2, Publisher: Sams Pub., 1994.

2
Course Outline
• Introduction to Basic Programming
– Variables and Data types
– Console IO Operations
– Operators and Expressions
• Control Flow Statements
– If Statement, Switch Statement, Unconditional
Branching using goto statement, While Loop, Do
While Loop, For Loop, Break and Continue

3
Course Outline
• Functions
– Introduction and Writing Functions
– Scope of Variables, Storage Classes, Pass by Value
and reference
– Recursion
• Arrays
– Arrays Declaration and Initialization
– Arrays as Function Parameters
– 2-Dimensional Array
4
Course Outline
• String Handling
– Standard String Library Functions
– Array of String
• Structures and Unions
– Declaring and Instantiating Structures
– Structure as Parameter and Pointer to Structure
– Enumerated Data Type
– Union

5
Course Outline
• Pointers
– Pointers as Function Parameter
– Pointer Arithmetic
– Pointers and Arrays
– Function Pointers

6
Introduction to Computer Software
• The computer hardware cannot think and make
decisions on its own.
• So, it cannot be used to analyze a given set of data and
find a solution on its own.
• The hardware needs a software (a set of programs) to
instruct what has to be done.
• A program is a set of instructions that is arranged in a
sequence to guide a computer to find a solution for the
given problem.
• The process of writing a program is called programming.

7
Introduction to Computer Software

8
Introduction to Computer Software
• Computer software is written by computer
programmers using a programming language.
• The programmer writes a set of instructions (program)
using a specific programming language. Such
instructions are known as the source code.
• Another computer program called a compiler is then
used on the source code, to transform the instructions
into a language that the computer can understand.
• The result is an executable computer program, which is
another name for software.
9
Introduction to Computer Software
Examples of computer software include:
• Computer Games
• Driver Software
• Educational Software
• Media Players and Media Development
Software
• Productivity Software
• Operating Systems software
10
Classification of Computer Software
• Application software is designed to solve a
particular problem for users.
– Examples of application software include
spreadsheets, database systems, desktop
publishing systems, program development
software, games, web browser

11
Classification of Computer Software
• System software provides a general
programming environment in which
programmers can create specific applications
to suit their needs.
– This environment provides new functions that are
not available at the hardware level and performs
tasks related to executing the application program.
– System software represents programs that allow
the hardware to run properly

12
Classification of Computer Software

13
BIOS
• BIOS or the basic input/output system is built into
the computer and is the first code run by the
computer when it is switched on.
• The key role of the BIOS is to load and start the
operating system.
• When the computer starts, the first function that
BIOS performs is to initialize and identify system
devices such as the video display card, keyboard and
mouse, hard disk, CD/DVD drive and other hardware
14
BIOS
BIOS performs the following functions:
• Initializes the system hardware
• The BIOS initializes system registers and power
management system
• Tests RAM and all the serial and parallel ports
• Initializes floppy disk drive and hard disk
controllers
• Displays system summary information
15
Operating System
• The primary goal of an operating system is to
make the computer system convenient and
efficient to use.
• The operating system offers generic services
to support user applications.
• An operating system ensures that the system
resources (like CPU, memory, I/O devices, etc)
are utilized efficiently.

16
Utility Software
• Utility software is used to analyze, configure, optimize and maintain the
computer system.
• Utility programs may be requested by application programs during their
execution. for multiple purposes.
• Some of them are listed below.
Disk defragmenters Disk checkers Disk cleaners
Disk space analyzers Disk partitions Backup utilities
Disk compression File managers System profilers
Anti-virus utilities Data compression utilities Cryptographic utilities
Launcher applications Registry cleaners Network utilities
Command line interface (CLI) Graphical user interface (GUI)

17
Compiler
• A compiler is a special type of program that
transforms source code written in a
programming language (the source language)
into machine language comprising of just two
digits- 1s and 0s (the target language).
• The resultant code in 1s and 0s is known as
the object code.
• The object code is the one which will be used
to create an executable program.
18
Compiler
• If the source code contains errors, then the
compiler will not be able to its intended task.
• Errors that limit the compiler in understanding a
program are called syntax errors.
• Syntax errors are like spelling mistakes, typing
mistakes, etc.
• Another type of error is logic error which occurs
when the program does not function accurately.
• Logic errors are much harder to locate and correct.

19
Interpreter
• The compiler translates instructions written in
high level programming language directly into
the machine language
• The interpreter translates the instructions into
an intermediate form, which it then executes.
• Usually, a compiled program executes faster
than an interpreted program

20
Linker
• Also called as link editor and binder
• A linker is a program that combines object modules
to form an executable program.
– Generally, in case of a large program, the programmers
prefer to break a code into smaller modules as this
simplifies the programming task.
– Eventually, when the source code of all the modules has
been converted into object code, you need to put all the
modules together. This is the job of the linker.
– Usually, the compiler automatically invokes the linker as
the last step in compiling a program.
21
Loader
• A loader is a special type of program that
copies programs from a storage device to
main memory, where they can be executed.
• Most loaders are transparent to the users.

22
Programming Languages
• A programming language is a language specifically
designed to express computations that can be
performed the computer.
• Programming languages are used to express
algorithms or as a mode of human communication.
• While high-level programming languages are easy
for the humans to read and understand, the
computer actually understands the machine
language that consists of numbers only.
23
Programming Languages
• In between the machine languages and high-
level languages, there is another type of
language known as assembly language.
• Assembly languages are similar to machine
languages, but they are much easier to
program in because they allow a programmer
to substitute names for numbers.

24
1st Generation Language: Machine
Language
• Machine language is the lowest level of
programming language.
• It is the only language that the computer
understands.
• All the commands and data values are
expressed using 1s and 0s.
• The main advantage of machine language is
that the code can run very fast and efficiently,
since it is directly executed by the CPU.
25
2nd Generation Language: Assembly
Language
• Assembly languages are symbolic
programming languages that use mnemonics
(symbols) to represent machine-language
instructions.
• Since assembly language is close to the
machine, it is also called low-level language.
• Basically, an assembly language statement
consists of a label, an operation code, and one
or more operands.
26
Assembly Language
• MOV AX,4 ;Stores the value 4 in the AX register
MOV BX,6 Stores the value 6 in the BX register
ADD AX,BX Add the contents of AX and BX register.
Store the result in AX register
• Assembly language is machine dependent
• The code written in assembly language will be very
efficient in terms of execution time and main
memory usage as the language is also close to the
computer

27
Assembly Language
• Programs written in assembly language need a
translator often known as the assembler to
convert them into machine language.

28
3rd Generation Language
• The third generation was introduced to make
the languages more programmer-friendly.
• The program statements are not closely
related to the internal characteristics of the
computer and is therefore often referred to
has high-level languages.

29
3rd Generation Language
• 3GLs made programming easier, efficient and less prone to
errors.
• Programs were written in an English-like manner, making
them more convenient to use and giving the programmer
more time to address a client's problems.
• Most of the programmers preferred to use general purpose
high level languages like BASIC (Beginners' All-purpose
Symbolic Instruction Code), FORTRAN, PASCAL, COBOL, C++
or Java to write the code for their applications.
30
• A translator is needed to translate the
instructions written in high level language into
computer-executable machine language.
• Such translators are commonly known as
interpreters and compilers.

31
4th Generation Language
• 4GLs is a little different from its prior generation because
they are basically nonprocedural so the programmers define
only what they want the computer to do, without supplying
all the details of how it has to be done.
Characteristics of such language include:
• the code comprising of instructions are written in English-like
sentences;
• they are nonprocedural
• the code is easier to maintain
• 4GL code enhances the productivity of the programmers as
they have to type fewer lines of code to get something done
32
4th Generation Language
• A typical example of a 4GL is the query
language that allows a user to request
information from a database with precisely
worded English-like sentences.
• The only down side of a 4GL is that it does not
make efficient use of machine’s resources.
• However, the benefit of executing a program
fast and easily far outweighs the extra costs of
running it.
33
5th Generation Language
• 5GLs are centered on solving problems using
constraints given to the program, rather than using an
algorithm written by a programmer.
• Most constraint-based and logic programming
languages and some declarative languages form a part
of the fifth-generation languages.
• 5GLs are widely used in artificial intelligence research.
• Typical examples of a 5GL include Prolog and Mercury.
34
Programming Language C
• C was developed in the early 1970s by Dennis
Ritchie at Bell Laboratories
• C was initially developed for writing system software
• Today, C has become a popular language and
various software programs are written using this
language.
• Many other commonly used programming
languages such as C++ and Java are also based on C

35
Characteristics of C
• A high level programming language
• C has only 32 keywords. This makes it relatively easy to learn
• Makes extensive use of function calls
• C is well suited for structured programming.
– In this programming approach, Unlike PASCAL it supports loose typing
(as a character can be treated as an integer and vice versa)
• Facilitates low level (bitwise) programming
• Supports pointers to refer computer memory, array, structures and
functions.
• C is a core language and is a portable language.

36
Uses of C
• C language is primarily used for system
programming.
– The portability, efficiency, the ability to access specific
hardware addresses and low runtime demand on system
resources makes it a good choice for implementing
operating systems and embedded system applications.
• C has been so widely accepted by professionals that
compilers, libraries, and interpreters of other
programming languages are often implemented in C.
37
Structure of a C Program

38
Structure of a C Program

39
Structure of a C Program
• Comments
– Text surrounded by /* and */ is ignored by
computer
– Used to describe program
• #include <stdio.h>
– Preprocessor directive
• Tells computer to load contents of a certain file
– <stdio.h> allows standard input/output
operations
40
Structure of a C Program
• int main()
– C++ programs contain one or more functions,
exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
– Braces ({ and }) indicate a block
• The bodies of all functions must be contained in braces

41
• printf( "Welcome to C!\n" );
– Instructs computer to perform an action
• Specifically, prints the string of characters within quotes
(“ ”)
– Entire line called a statement
• All statements must end with a semicolon (;)
– Escape character (\)
• Indicates that printf should do something out of the
ordinary
• \n is the newline character

42
• return 0;
– A way to exit a function
– return 0, in this case, means that the program
terminated normally
• Right brace }
– Indicates end of main has been reached

43

You might also like