5. What do we learn?
1. Introduction and Fundamental of C
2. Data types, Operators, Expressions
3. Condition and branching
4. Iteration, loops
5. 1-D Array
6. Functions
7. Recursion ,
8. Strings
9. Pointers
10.2D-Array
11.Structures
12.File handling
13.Input/Output
14.Searching
15.Sorting
6. WHAT IS A COMPUTER?
Something that computes something.
E.g. an orrery:
https://en.wikipedia.org/wiki/Orrery
https://www.youtube.com/watch?v=yKS7C0dC-bU
https://www.youtube.com/watch?v=yKS7C0dC-bU
8. WHAT IS A COMPUTER?
Something that computes something.
https://en.wikipedia.org/wiki/Enigma_machine
E.g. the enigma machine:
https://www.youtube.com/watch?v=ASfAPOiq_eQ&feature=youtu.be&t=129
9. AN ABSTRACT VIEW OF A COMPUTER
Computer
Input Output
Orrery
Time
Positions of
planets
Enigma
Mode +
message
En-/decrypted
message
10. AN ABSTRACT VIEW OF A COMPUTER
Computer
Input Output
Does this view fit modern computers?
11. MODERN COMPUTERS
Modern computers are general-purpose computers.
• The software (the program)
tells the hardware what to
compute.
• The hardware in the
computer can be used
to compute things.
The program
12. HARDWARE ♥ SOFTWARE
• A program (the software) consists of a sequence of instructions.
• The hardware executes these instructions, one after another.
Many modern computers support a set of instructions called X86.
• See all of the instructions at.
https://en.wikipedia.org/wiki/X86_instruction_listings
13. SAMPLE PROGRAM
Instructions
0: SET 0, #9
1: ADD 1, #9
2: ADD 2, #9
3: SUB 3, #9
4: JINZ #9, #7
5: SET 4, #10
6: JUMP #8
7: SET 5, #10
8: FINISH
9:
10:
- 1
0 - 3
- 0
4
Hard to read &
hard to write.
sum = 0
sum += 1
sum += 2
if sum == 3:
answer = "Yes"
else:
answer = "No"
Python
Checking if the sum of the integers between 0 and 2 is 3.
↓
Programming
languages
invented.
18. Organization of a Computer
• Five classic components of a computer – input, output, memory,
datapath, and control
datapath +
control =
processor
(CPU)
20. Levels of Abstraction
20
Microarchitecture
ISA (Architecture)
Program/Language
Algorithm
Problem
Logic
Circuits
Runtime System
(VM, OS, MM)
Electrons
“The purpose of computing is insight” (Richard Hamming)
We gain and generate insight by solving problems
How do we ensure problems are solved by electrons?
26. What is a Programming
Language?
• A programming language is a notational system
for describing computation in machine-readable
and human-readable form.
• Most of these forms are high-level languages,
which is the subject of the course.
• Assembly languages and other languages that are
designed to more closely resemble the computer’s
instruction set than anything that is human-
readable are low-level languages.
27. Why Study Programming Languages?
• In 1969, Sammet listed 120 programming
languages in common use – now there are many
more( around 900)
• Most programmers never use more than a few.
– Some limit their career’s to just one or two.
• The gain is in learning about their underlying
design concepts and how this affects their
implementation.
28. The Six Primary Reasons
• Increased ability to express ideas
• Improved background for choosing appropriate
languages
• Increased ability to learn new languages
• Better understanding of significance of
implementation
• Better use of languages that are already known
• Overall advancement of computing
29. Reason #1 - Increased ability to
express ideas
• The depth at which people can think is
heavily influenced by the expressive power
of their language.
• It is difficult for people to conceptualize
structures that they cannot describe,
verbally or in writing.
30. Expressing Ideas as Algorithms
• This includes a programmer’s to develop
effective algorithms
• Many languages provide features that can
waste computer time or lead programmers
to logic errors if used improperly
– E. g., recursion in C, Pascal etc.
– E. g., GoTos in FORTRAN, etc.
31. Reason #2 - Improved background for
choosing appropriate languages
• Many professional programmers have a
limited formal education in computer
science, limited to a small number of
programming languages.
• They are more likely to use languages with
which they are most comfortable than the
most suitable one for a particular job.
32. Reason #3 - Increased ability to
learn new languages
• A thorough understanding of programming
language design and implementation makes it
easier to learn new languages.
33. Learning a New Language
• It is easier to learn a new language if you
understand the underlying structures of
language.
Examples:
– It is easier for a BASIC programmer to learn
FORTRAN than C.
– It is easier for a C++ programmer to learn Java.
– It is easier for a Scheme programmer to learn LISP.
34. Reason #4 - Better understanding of
significance of implementation
• It is often necessary to learn about language
implementation; it can lead to a better
understanding of why the language was
designed the way that it was.
• Fixing some bugs requires an understanding
of implementation issues.
35. Reason #5 - Better use of languages
that are already known
• To allow a better choice of programming
language
• Some languages are better for some jobs than
others.
– Example –C- Systems-level and numeric computing
– FORTRAN for Scientific calculations,
– COBOL and RPG for report generation,
– LISP and PROLOG for AI, etc.
36. Better Use of a Language
• To improve your use of existing
programming language
• By understanding how features are
implemented, you can make more efficient
use of them.
• Examples:
• Creating arrays, strings, lists, records.
• Using recursions, object classes, etc.
37. Reason #6 - Overall
advancement of computing
• Frequently, the most popular language may
not be the best language available.
• E.g., ALGOL 60 did NOT displace Fortran.
– They had difficulty understanding its
description and they didn’t see the significance
of its block structure and well-structured
control statements until many years later.
38. Purpose Examples
• General-purpose • Python, C, Java, Rust, Go
• Scripting • JavaScript, Bash, Perl
• Functional • Haskell, Lisp, OCaml
• Educational • Scratch, Logo
• Hardware/Embedded • VHDL, Verilog, Assembly
Examples of Language Families
41. Key Advantages of C Language
1. High Performance
•C is compiled directly to machine code → executes very fast.
•Used in performance-critical applications like operating systems,
game engines, and embedded systems.
2. Low-Level Access to Memory
•Offers direct memory manipulation using pointers.
•Can interact closely with hardware — essential for device drivers
and embedded programming
3. Portability
•Code written in C can be compiled and run on many platforms
with little or no modification.
•The C standard library is available across most platforms.
42. Key Advantages of C Language
4. Foundation for Other Languages
Languages like C++, Java, Python, Rust, Go have C-like syntax
or are implemented in C.
Learning C helps you understand how high-level languages work
under the hood.
5. Modular and Structured
C supports structured programming with functions, loops, and
conditional statements.
Encourages modular code with separate source and header files.
6. System-Level Programming
Ideal for writing:
Operating systems (Linux, UNIX, Windows core)
Compilers and interpreters
Embedded firmware
43. Key Advantages of C Language
7. Deterministic Behavior
No garbage collector or hidden runtime processes.
Full control over CPU and memory usage.
8. Large Ecosystem & Tools
Rich ecosystem of libraries, compilers (GCC, Clang), and
debuggers (GDB).
Well-supported by IDEs, static analyzers, and embedded
toolchains.
45. C in the Frontend
✅
Where How C is Involved
GUI toolkits GTK+, FLTK, X11 — written in C
Browsers
Chrome (Blink), Firefox (Gecko) — parts in
C/C++
WebAssembly
C code can be compiled to WebAssembly
via Emscripten
Game UIs Rendered with engines written in C/C++
Embedded GUI
LVGL, µGFX — lightweight C libraries for
UI on microcontrollers
Note: rarely used directly, but plays an indirect role
46. C in the Backend
Area Examples
Operating Systems
Linux, Windows kernel, Unix,
macOS
Embedded Systems IoT devices, routers, controllers
Databases MySQL, PostgreSQL (core in C)
Compilers & Runtimes GCC, Clang, JVM internals
Web Servers NGINX, Apache (written in C)
Networking Software
TCP/IP stack, DNS servers, SSH,
etc.
Game Engines Some parts of Unreal, Doom, etc.
High-performance libraries
OpenSSL, zlib, BLAS, LAPACK,
SQLite
✅
50. The Compiling Process-
languages that Use This Compile-Then-Link Model
Language Source File Compiler Output Example
C .c gcc, clang a.out, main.exe
C++ .cpp g++, clang++ a.out, main.exe
Fortran .f, .f90 gfortran a.out, program.exe
Rust .rs rustc main.exe, main
Go .go go build
main (native
binary)
Ada .adb gnatmake program
Swift .swift swiftc program
Assembly .s, .asm as, nasm, masm program
52. The Pure Interpretation Process-Examples of Purely
Interpreted Languages
Language Notes
Python
Interpreted by CPython (also has JIT
versions)
Ruby
Interpreted by MRI (Matz’s Ruby
Interpreter)
LISP Originally interpreted, especially in AI
JavaScript
Interpreted by browsers (V8,
SpiderMonkey)
MATLAB
Interprets commands for numeric
computing
Bash/Shell Shell scripts are interpreted line by line
56. Levels of Representation
High Level Language
Program
Assembly Language
Program
Machine Language
Program
Control Signal
Specification
Compiler
Assembler
Machine Interpretation
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
lw $15, 0($2)
lw $16, 4($2)
sw $16, 0($2)
sw $15, 4($2)
0000 1001 1100 0110 1010 1111 0101 1000
1010 1111 0101 1000 0000 1001 1100 0110
1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
°
°
ALUOP[0:3] <= InstReg[9:11] & MASK
[i.e.high/low on control lines]
57. Compile time: What does gcc do?
% gcc hello.c
hello.c
gcc
a.out
57
“Source”
Program in C
#include <stdio.h>
void func1(int a, char *b)
{
if(a > 0)
{ *b = ‘a’; }
}
int main()
{…..
func1();
printf(“abc”);
}
“Executable”:
Equivalent program
in machine
language
0000 1001 1100 0110
1010 1111 0101 1000
1010 1111 0101 1000
0000 1001 1100 0110
1100 0110 1010 1111
0101 1000 0000 1001
0101 1000 0000 1001
1100 0110 1010 1111
58. Steps in gcc
• The translation is actually done in a number of steps
hello.c
a.out
58
gcc
hello.s
Assembler(as)
Linker
(ld)
hello.o
Compiler
(cpp)
59. Steps in gcc
• Ask compiler to show temporary files:
% gcc –S hello.c (gives hello.s – assembly code)
% gcc –c hello.c (gives hello.o – object module)
% gcc –o prog_hello hello.c (gives prog_hello - named
executable)
hello.c
a.out
gcc
hello.s
as
cpp
cc1
ld
hello.o
60. Include code written by others
• Code written by others (libraries) can be included
• ld (linkage editor) merges one or more object files with the
relevant libraries to produce a single executable
hello.c
a.out
60
gcc
hello.s
as
cpp
cc1
ld
Library files
e.g. math.o:
the math
library
hello.o
61. Compilation Phases
Option Description Example
-E Preprocess only gcc -E hello.c -o hello.i
-S Compile to assembly gcc -S hello.c -o hello.s
-c Compile to object code only gcc -c hello.c -o hello.o