CS1101:
Foundations of Programming
Logistics
Introduction to c language from lecture slides
4
Our Mantra
Computer Science
Science is about learning by
doing ... experiments!
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
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
Introduction to c language from lecture slides
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
AN ABSTRACT VIEW OF A COMPUTER
Computer
Input Output
Orrery
Time
Positions of
planets
Enigma
Mode +
message
En-/decrypted
message
AN ABSTRACT VIEW OF A COMPUTER
Computer
Input Output
Does this view fit modern computers?
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
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
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.
What’s Inside the Box?
Introduction to c language from lecture slides
What is inside the box?
Courtesy, Intel
Function Units in a Computer
Organization of a Computer
• Five classic components of a computer – input, output, memory,
datapath, and control
 datapath +
control =
processor
(CPU)
Computer Architecture
Computer
Architecture
I/O system
Instr. Set Proc.
Compiler
Operating
System
Application
Logic Design
Circuit Design
Instruction Set Architecture
Firmware
Implementation
Layout
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?
From Electrons & Holes to a
Multiplayer Video Game
Systems
Introduction to c language from lecture slides
Introduction to c language from lecture slides
Introduction to c language from lecture slides
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.
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.
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
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.
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.
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.
Reason #3 - Increased ability to
learn new languages
• A thorough understanding of programming
language design and implementation makes it
easier to learn new languages.
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.
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.
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.
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.
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.
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
Why C
Tiobe
Index
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.
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
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.
Why do we learn?
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
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
✅
Programming Domains
• Scientific Applications
• Business Applications
• Artificial Intelligence
• Web Software
Implementation Methods
• Compilation
• Pure Interpretation
• Hybrid Implementation Systems
The Compiling Process
Source
Code
Assembler version
Object
Module
Compiler Linker
Executable
version
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
The Pure Interpretation Process
Source
Code
Interpreter Output
Input
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
The Hybrid Interpretation
Process
Source
Code
Intermediate
Version
Interpreter Interpreter Output
Input
The Hybrid Interpretation Process-Examples of Hybrid
Languages
Language Intermediate Code
Virtual Machine /
Interpreter
Java Bytecode (.class)
Java Virtual Machine
(JVM)
Python Bytecode (.pyc)
Python Virtual Machine
(PVM)
C# Common IL (MSIL)
.NET CLR (Common
Language Runtime)
Scala Bytecode JVM
Kotlin Bytecode JVM
MATLAB P-code MATLAB runtime
Execution Cycle
Instruction
Fetch
Instruction
Decode
Operand
Fetch
Execute
Result
Store
Next
Instruction
Obtain instruction from program storage
Determine required actions and instruction size
Locate and obtain operand data
Compute result value or status
Deposit results in storage for later use
Determine successor instruction
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]
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
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)
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
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
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
Optimization Levels
Option Description Example
-O0 No optimization gcc -O0 hello.c -o
hello
-O2 Moderate
optimization
gcc -O2 hello.c -o
hello
-O3 High-level
optimization
gcc -O3 hello.c -o
hello
Machine-Specific Options (-m*)
Option Description Example
-m32 Compile for 32-bit gcc -m32 hello.c -o
hello
-m64 Compile for 64-bit gcc -m64 hello.c -o
hello
Translations
 High-level language program (in C)
swap (int v[], int k)
{ int temp;
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
}
 Assembly language program (for MIPS )
swap: sll $2, $5, 2
add $2, $4, $2
lw $15, 0($2)
lw $16, 4($2)
sw $16, 0($2)
sw $15, 4($2)
jr $31
 Machine (object, binary) code (for MIPS )
000000 00000 00101 0001000010000000
000000 00100 00010 0001000000100000
. . .
C compiler
assembler
one-to-many
one-to-one
Performance: C versus Assembly
Language
0
1
2
3
4
5
0 20 40 60 80 100
Number of calls (in millions)
Time
(seconds)

More Related Content

PPTX
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
PPT
Programming Language Introduction Lecture
PPT
software principle programming language
PPT
Python and principle of programming language.ppt
PPT
272l1ggtwtyehrnbrbbhrhrbhekjjbdc to use.ppt
PPT
272l1fghhsssssssdddeedfffwasfgc to use.ppt
PPT
Introduction to Computer
PPT
Ppl 13 july2019
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
Programming Language Introduction Lecture
software principle programming language
Python and principle of programming language.ppt
272l1ggtwtyehrnbrbbhrhrbhekjjbdc to use.ppt
272l1fghhsssssssdddeedfffwasfgc to use.ppt
Introduction to Computer
Ppl 13 july2019

Similar to Introduction to c language from lecture slides (20)

PPTX
L1.1 Introduction to Programming Languages.pptx
PDF
Computer programing 111 lecture 1
PPTX
C_Programming_Notes_ICE
PDF
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy1.pdf
PPTX
Expection Setting - 1st ppt. pptx
PPTX
Introduction-to-Programming-Languages.pptx
PPTX
Principles of object oriented programming, object-oriented programming paradi...
PDF
PPTX
Programming Fundamentals and Programming Languages Concepts
PPTX
lecture Slides - Week 1.programming fundamentals
PPTX
Introduction to c language
PDF
Introduction to C Programming (1).pdf
DOC
Notes of c programming 1st unit BCA I SEM
PPT
Book ppt
PPT
PPTX
computer programming computer programmin
DOCX
Fundamentals of Programming language.docx
DOCX
Learn C Programming Full Course Free
PPTX
Programming
L1.1 Introduction to Programming Languages.pptx
Computer programing 111 lecture 1
C_Programming_Notes_ICE
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy1.pdf
Expection Setting - 1st ppt. pptx
Introduction-to-Programming-Languages.pptx
Principles of object oriented programming, object-oriented programming paradi...
Programming Fundamentals and Programming Languages Concepts
lecture Slides - Week 1.programming fundamentals
Introduction to c language
Introduction to C Programming (1).pdf
Notes of c programming 1st unit BCA I SEM
Book ppt
computer programming computer programmin
Fundamentals of Programming language.docx
Learn C Programming Full Course Free
Programming
Ad

Recently uploaded (20)

PPT
Storage Area Network Best Practices from HP
PDF
Chapter 1: computer maintenance and troubleshooting
PDF
Human Computer Interaction Miterm Lesson
PDF
The AI Revolution in Customer Service - 2025
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Gestión Unificada de los Riegos Externos
PDF
Advancements in abstractive text summarization: a deep learning approach
PPTX
Information-Technology-in-Human-Society (2).pptx
PDF
Intravenous drug administration application for pediatric patients via augmen...
PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
Examining Bias in AI Generated News Content.pdf
PDF
Altius execution marketplace concept.pdf
PDF
Ericsson 5G Feature,KPIs Analysis_ Overview, Dependencies & Recommendations (...
PDF
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PPTX
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
PDF
CEH Module 2 Footprinting CEH V13, concepts
PDF
Internet of Things (IoT) – Definition, Types, and Uses
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
Storage Area Network Best Practices from HP
Chapter 1: computer maintenance and troubleshooting
Human Computer Interaction Miterm Lesson
The AI Revolution in Customer Service - 2025
Build automations faster and more reliably with UiPath ScreenPlay
Gestión Unificada de los Riegos Externos
Advancements in abstractive text summarization: a deep learning approach
Information-Technology-in-Human-Society (2).pptx
Intravenous drug administration application for pediatric patients via augmen...
Optimizing bioinformatics applications: a novel approach with human protein d...
NewMind AI Journal Monthly Chronicles - August 2025
Examining Bias in AI Generated News Content.pdf
Altius execution marketplace concept.pdf
Ericsson 5G Feature,KPIs Analysis_ Overview, Dependencies & Recommendations (...
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
Introduction to MCP and A2A Protocols: Enabling Agent Communication
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
CEH Module 2 Footprinting CEH V13, concepts
Internet of Things (IoT) – Definition, Types, and Uses
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
Ad

Introduction to c language from lecture slides

  • 4. 4 Our Mantra Computer Science Science is about learning by doing ... experiments!
  • 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.
  • 16. What is inside the box? Courtesy, Intel
  • 17. Function Units in a Computer
  • 18. Organization of a Computer • Five classic components of a computer – input, output, memory, datapath, and control  datapath + control = processor (CPU)
  • 19. Computer Architecture Computer Architecture I/O system Instr. Set Proc. Compiler Operating System Application Logic Design Circuit Design Instruction Set Architecture Firmware Implementation Layout
  • 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?
  • 21. From Electrons & Holes to a Multiplayer Video Game
  • 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
  • 39. Why C
  • 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.
  • 44. Why do we learn?
  • 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 ✅
  • 47. Programming Domains • Scientific Applications • Business Applications • Artificial Intelligence • Web Software
  • 48. Implementation Methods • Compilation • Pure Interpretation • Hybrid Implementation Systems
  • 49. The Compiling Process Source Code Assembler version Object Module Compiler Linker Executable version
  • 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
  • 51. The Pure Interpretation Process Source Code Interpreter Output Input
  • 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
  • 54. The Hybrid Interpretation Process-Examples of Hybrid Languages Language Intermediate Code Virtual Machine / Interpreter Java Bytecode (.class) Java Virtual Machine (JVM) Python Bytecode (.pyc) Python Virtual Machine (PVM) C# Common IL (MSIL) .NET CLR (Common Language Runtime) Scala Bytecode JVM Kotlin Bytecode JVM MATLAB P-code MATLAB runtime
  • 55. Execution Cycle Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value or status Deposit results in storage for later use Determine successor instruction
  • 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
  • 62. Optimization Levels Option Description Example -O0 No optimization gcc -O0 hello.c -o hello -O2 Moderate optimization gcc -O2 hello.c -o hello -O3 High-level optimization gcc -O3 hello.c -o hello
  • 63. Machine-Specific Options (-m*) Option Description Example -m32 Compile for 32-bit gcc -m32 hello.c -o hello -m64 Compile for 64-bit gcc -m64 hello.c -o hello
  • 64. Translations  High-level language program (in C) swap (int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; }  Assembly language program (for MIPS ) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31  Machine (object, binary) code (for MIPS ) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 . . . C compiler assembler one-to-many one-to-one
  • 65. Performance: C versus Assembly Language 0 1 2 3 4 5 0 20 40 60 80 100 Number of calls (in millions) Time (seconds)