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

SMA 2175 Lecture 1_Introduction

The document provides an introduction to programming, specifically focusing on the C programming language. It covers the basics of computers, types of programming languages, and the features and history of C, highlighting its importance as a foundational language for modern programming. Additionally, it explains the structure of a C program and the execution flow from source code to executable code.

Uploaded by

samwel.ochieng21
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

SMA 2175 Lecture 1_Introduction

The document provides an introduction to programming, specifically focusing on the C programming language. It covers the basics of computers, types of programming languages, and the features and history of C, highlighting its importance as a foundational language for modern programming. Additionally, it explains the structure of a C program and the execution flow from source code to executable code.

Uploaded by

samwel.ochieng21
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

SMA 2175:

INTRODUCTION TO PROGRAMMING

TOPIC: INTRODUCTION

BY

JULIET MOSO
WHAT IS A COMPUTER?
 Computer

 Device capable of performing computations


and making logical decisions
 Computers process data under the control
of sets of instructions called computer
programs
 Hardware

 Various devices comprising a computer


 Keyboard, screen, mouse, disks, memory,
CD-ROM, and processing units
 Software

 Programs that run on a computer


A LAYERED VIEW OF THE
COMPUTER

Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs,
etc…
System Software
Compilers,
Interpreters,Preprocessors, etc.
Operating System, Device Drivers
Machine with all its
hardware
COMPUTER ORGANIZATION
 Six logical units in every computer:
1. Input unit
 Obtains information from input devices (keyboard,
mouse)
2. Output unit
 Outputs information (to screen, to printer, to control
other devices)
3. Memory unit
 Rapid access, low capacity, stores input information
4. Arithmetic and logic unit (ALU)
 Performs arithmetic calculations and logic decisions
5. Central processing unit (CPU)
 Supervises and coordinates the other sections of the
computer
6. Secondary storage unit
 Cheap, long-term, high-capacity storage
 Stores inactive programs
PROGRAMS
 Programsare written in programming
languages (PL)
 Pieces of the same program can be written in
different PLs
 Languages closer to the machine can be more

efficient
 As long as they agree on how to communicate

A PL is
A special purpose and limited language
 A set of rules and symbols used to construct a
computer program
 A language used to interact with the computer
TYPES OF COMPUTER LANGUAGES
There are three types of languages
 Machine Language
 Uses binary code
 Machine-dependent
 Not portable
 Assembly Language
 Uses mnemonics
 Machine-dependent
 Not usually portable
 High-Level Language (HLL)
 Uses English-like language
 Machine independent
 Portable (but must be compiled for different
platforms)
 Examples: Pascal, C, C++, Java, Fortran, . . .
MACHINE LANGUAGE
 The representation of a computer program which is
actually read and understood by the computer.
A program in machine code consists of a sequence of
machine instructions which specify what the
computer should do.
 Instructions:
 Machine instructions are in binary code
 Instructions specify operations and memory cells
involved in the operation
Example:
Operation Address

0010 0000 0000 0100

0100 0000 0000 0101

0011 0000 0000 0110


ASSEMBLY LANGUAGE
 A symbolic representation of the machine
language of a specific processor.
 Is converted to machine code by an assembler.
 Usually, each line of assembly code produces one
machine instruction (One-to-one correspondence).
 Programming in assembly language is slow and
error-prone but is more efficient in terms of
hardware performance.
 Mnemonic representation of the instructions and
data

 Example:
Load Price
Add Tax
Store Cost
HIGH-LEVEL LANGUAGE
 A programming language which use statements
consisting of English-like keywords such as "FOR",
"PRINT" or “IF“, ... etc.
 Each statement corresponds to several machine
language instructions (one-to-many
correspondence).
 Much easier to program than in assembly
language.
 Data are referenced using descriptive names
 Operations can be described using familiar
symbols

 Example:
Cost := Price + Tax
C PROGRAMMING LANGUAGE
 What is C?
C is a structured, relatively low-level, portable
programming language.

 Why study C?
 Many popular software tools are written in C.
 Has strongly influenced many other
languages.
 C-shell, java, C++, Perl, etc.
 Forces the user to understand fundamental
aspects of programming.
 Very concise language.
C PROGRAMMING LANGUAGE
 The C Language is developed for creating system
applications that directly interact with the hardware
devices such as drivers, kernels, etc.

 C programming is considered as the base for other


programming languages, that is why it is known as
the mother language.

 It can be defined by the following ways:

1. Mother language
2. System programming language
3. Procedure-oriented programming language
4. Structured programming language
5. Mid-level programming language
C AS A MOTHER LANGUAGE
C language is considered as the mother
language of all the modern programming
languages because most of the compilers, JVMs,
Kernels, etc. are written in C language,

 Alsomost of the programming languages follow


C syntax, for example, C++, Java, C#, etc.

 Itprovides the core concepts like the array,


strings, functions, file handling, etc. that are
being used in many languages.
C AS A SYSTEM PROGRAMMING
LANGUAGE
 A system programming language is used to
create system software.

 C language can be used to do low-level


programming (for example driver and kernel).

 It is generally used to create hardware devices,


OS, drivers, kernels, etc. For example, Linux
kernel is written in C.

 It can't be used for internet programming like


Java, .Net, PHP, etc.
C AS A PROCEDURAL LANGUAGE
A procedure is known as a function, method,
routine, subroutine, etc.

A procedural language specifies a series of


steps for the program to solve the problem.

A procedural language breaks the program


into functions, data structures, etc.

C is a procedural language. In C, variables and


function prototypes must be declared before
being used.
C AS A STRUCTURED PROGRAMMING
LANGUAGE
A structured programming language is a subset
of the procedural language.

 Structure means to break a program into parts


or blocks so that it may be easy to understand.

 Inthe C language, we break the program into


parts using functions.

 It
makes the program easier to understand and
modify.
C AS A MID-LEVEL PROGRAMMING LANGUAGE
 C is considered as a middle-level language because it
supports the feature of both low-level and high-level
languages.

 C language program is converted into assembly code,


it supports pointer arithmetic (low-level), but it is
machine independent (a feature of high-level).

 A Low-level language is specific to one machine, i.e.,


machine dependent. It is fast to run, but not easy to
understand.

 A High-Level language is not specific to one machine,


i.e., machine independent. It is easy to understand.
HISTORY OF C LANGUAGE
 C was developed in 1972 by Dennis Ritchie
 It was developed to overcome the problems of

previous languages such as B, BCPL etc.


 Used to develop UNIX

 Used to write modern operating systems

 C is hardware independent (portable)

 Standardization
 Many slight variations of C existed, and were
incompatible
 Committee formed to create a "unambiguous,
machine-independent" definition
 Standard created in 1989, updated in 1999
FEATURES OF C LANGUAGE
1) Simple
 C provides structured approach (to break the problem into parts),

rich set of library functions, data types etc.

2) Machine Independent or Portable


 C programs can be executed in many machines with little bit or

no change. But it is not platform-independent.

3) Mid-level programming language


 C is also used to do low level programming. It is used to develop

system applications such as kernel, driver etc. It also supports


the feature of high level language.

4) Structured programming language


 In C we can break the program into parts using functions. So, it is

easy to understand and modify.


FEATURES OF C LANGUAGE CONT.
5) Rich Library
 C provides a lot of inbuilt functions that makes the development

fast.
6) Memory Management
 It supports dynamic memory allocation. In C language, we can

free the allocated memory at any time by calling the free()


function.
7) Speed
 The compilation and execution time of C language is fast.

8) Pointers
 We can directly interact with the memory by using the pointers.

We can use pointers for memory, structures, functions, array


etc.
9) Recursion
 In C, we can call the function within the function. It provides

code reusability for every function.


10) Extensible
FIRST C PROGRAM
#include <stdio.h>
int main(){
printf("Hello C Language");
return 0;
}
 #include <stdio.h> includes the standard input
output library functions. The printf() function is defined
in stdio.h .
 The main() function is the entry point of every
program in c language.
 The printf() function is used to print data on the
console.
 The return 0 statement, returns execution status to
the OS. The 0 value is used for successful execution
C PROGRAM EXECUTION FLOW
1) C program (source code) is sent to preprocessor first. The
preprocessor is responsible to convert preprocessor directives
into their respective values. The preprocessor generates an
expanded source code.

2) Expanded source code is sent to compiler which compiles the


code and converts it into assembly code.

3) The assembly code is sent to assembler which assembles the


code and converts it into object code. Now a simple.obj file is
generated.

4) The object code is sent to linker which links it to the library


such as header files. Then it is converted into executable
code. A simple.exe file is generated.

5) The executable code is sent to loader which loads it into


THE C STANDARD LIBRARY
 C programs consist of pieces/modules called functions
 A programmer can create his own functions
 Advantage: the programmer knows exactly how it

works
 Disadvantage: time consuming

 Programmers will often use the C library functions


 Use these as building blocks

 Avoid re-inventing the wheel


 If a premade function exists, generally best to use

it rather than write your own


 Library functions carefully written, efficient, and

portable

You might also like