ِﺑِﺳْ مِ ٱ ﱠٰ ِ ٱﻟرﱠ ﺣْ َٰﻣ ِن ٱﻟرﱠ ﺣِﯾم
In the name of Allah, Most Gracious, Most Merciful
CSE 4107
Structured Programming I
Topic: Introducing C & C fundamentals
Asaduzzaman Herok
Lecturer | CSE | IUT
asaduzzaman34@[Link]
Programming Language
What is Language?
Language is a mode of communication that is used to share ideas, opinions
with each other.
What is Programming Language?
A programming language is a computer language that is used by programmers
(developers) to communicate with computers.
It is a set of instructions written in any specific language ( C, C++, Java,
Python) to perform a specific task.
Source: [Link]
Asaduzzaman Herok, Lecturer
03 September, 2024 2
Department of Computer Science and Engineering, IUT
Generations of Programming Language
➔ First Generation: Machine Language
◆ Consist of binary code (0s and 1s) that directly
corresponds to the internal instructions
understood by a specific computer processor.
➔ Second Generation: Assembly Language
◆ Uses symbolic instructions that are easier to
understand and remember than binary code.
Source:
[Link]
ng-languages-bed30d19ea8e
Source:
[Link]
age-8144ce1dfb0e
Asaduzzaman Herok, Lecturer
03 September, 2024 3
Department of Computer Science and Engineering, IUT
Generations of Programming Language
➔ Third Generation: High-Level Languages ➔ Fifth Generation: Natural Language
◆ These languages use English-like keywords Programming
and syntax, making them much more readable ◆ Aims to allow humans to communicate with
and writable for humans. computers using natural language like English.
NLP is still in its early stages of development.
➔ Fourth Generation: Very High-Level
Languages
◆ Even more user-friendly and domain-specific
than third-generation languages. They often
focus on specific tasks or problem domains,
such as database management, web SQL: Structured Query Language
development, or scientific computing.
Source:
[Link]
ng-languages-bed30d19ea8e
C++
Asaduzzaman Herok, Lecturer
03 September, 2024 4
Department of Computer Science and Engineering, IUT
Introducing C
What is C? When someone says “I want a programming
A widely used programming language language in which I need only say what I wish
developed in the early 1970s at Bell done,” give him a lollipop.
Laboratories. (Alan Perlis)
Source: Reddit:r/ProgrammerHumor
Asaduzzaman Herok, Lecturer
03 September, 2024 5
Department of Computer Science and Engineering, IUT
History of C
Origin:
● C is a by-product of UNIX operating system, developed at Bell Lab by Ken Thompson, Dennis Ritchie and others.
● Ken Thompson wrote the original UNIX OS (written in assembly) for mini computer (DEC PDP-7) with 8K words
main memory.
● For further development of UNIX OS a small high level language called B was created by Thompson.
● In 1970 Bell Lab got a new mini computer PDP-11 for the UNIX project. B was running in PDP-11
● When B was not well suited for PDP-11, Ritchie developed extended version of B called NB (New B)
● Later NB (New B) was renamed to C.
● In 1973 C became stable enough for rewriting UNIX.
● After creating C compilers for different machines, UNIX got running on those machines as well.
Standardization:
● During 1970s and 1977-1979 C continued evolving much. In 1978 first book on C was released.
● By 1980 C expanded beyond the UNIX OS.
● US standard for C began in 1983 under American National Standards Institute (ANSI). This version is referred to as
C89 or C90
● Later the standard C99 came with some major differences from C89
● Today (3rd Sep 2024) the latest standard of C is C23.
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 6
Department of Computer Science and Engineering, IUT
Strengths and Weakness of C
Philosophy of C:
● A low-level language: Suitable for systems (OS) programming as it provides access to machine level concepts like
bytes and addresses in memory. C programs are fast.
● A small language: Provides a more limited set of features than many other languages.
● A permissive language: Assumes that you know what you are doing, allowing you a wider degree of freedom.
Strength:
● Efficiency:C programs can run quickly in limited amounts of memory.
● Portability: C programs are portable from one type of computer to another. Thanks to the C compilers being small
and easy to write.
● Power: Large collection of data types and operators.
● Flexibility: Flexible to use from System programming to all kinds of applications from embedded systems to
commercial data processing.
● Standard Library: Contains hundreds of functions for different task.
● Integration with UNIX: Is powerful with combination of UNIX (like Linux)
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 7
Department of Computer Science and Engineering, IUT
Strengths and Weakness of C
Weakness:
● Error-prone: Programming mistakes that would be caught in many languages, can’t be detected by C compilers. It's
more like assembly language.
● Difficult to understand: Provides a more limited set of features than many other
languages.
Source:
[Link]
zahid-hasan_meme-template/
Printing all solution to Eight Queen problem
● Difficult to modify: Lacks the feature of Class and Packaging for better maintainability.
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 8
Department of Computer Science and Engineering, IUT
C Fundamentals
Writing a Simple Program:
Follow the white board
Compiling and Linking:
3 steps to convert the program (written on the board) to machine executable form:
● Preprocessing: First the program (written as text) goes through a preprocessor that only process the
commands beginning with # (known as directives). It is like an editor.
● Compiling: The modified version of the program goes to the compiler which translates it into the machine
instructions (object code).
● Linking: A Linker combines the object code with additional code needed to yield a complete executable
program.
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 9
Department of Computer Science and Engineering, IUT
C Fundamentals
General Form of a Simple Program:
Follow the white board
● Directives
● Functions
● Statements
● Printing Strings
● Blocks
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 10
Department of Computer Science and Engineering, IUT
C Fundamentals
Comments:
Follow the white board
● Single line comment
● Multiline comment
● Boxed comment
● Simplified boxed comment
● Uncaught error in multiline comment.
● Nested Comments
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 11
Department of Computer Science and Engineering, IUT
C Fundamentals
Variables and Assignments:
Follow the white board
● Types: int, float, char
● Rounding error in float
● Declarations: Same type, Different type
● Assignments: Order matters while assigning and declaring. Assignment at the time of declaration.
● Printing variable values: printf function, format specifier, digit control after decimal point.
● Initialization
● Printing Expressions
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 12
Department of Computer Science and Engineering, IUT
C Fundamentals
Reading Input:
Follow the white board
● Format String
● Reading input:scanf function, format specifier.
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 13
Department of Computer Science and Engineering, IUT
C Fundamentals
Defining Names for Constants:
Follow the white board
● Macro definition: #define
● Naming convention
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 14
Department of Computer Science and Engineering, IUT
C Fundamentals
Identifiers:
Follow the white board
● Naming of variables, functions, macros
● May contain letters, digits and underscores
● Must begin with letter or underscore
● Case sensitivity
● No limits on the maximum length of identifiers
(compiler dependence)
● An identifier cannot be a keyword
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 15
Department of Computer Science and Engineering, IUT
C Fundamentals
Layout of a C Program:
Follow the white board
● C program is a series of token.
● Identifiers, keywords, operators (like + - * / ), punctuations (like comma, semicolon), string literals
● Indentations, Dividing statements in multiple line.
● Example:
printf ( “Height: %d\n” , height ) ;
1 2 3 4 5 6 7
7 Tokens. Token 1 and 5 are identifiers, token 3 string literal, token 2,4,6,7 are punctuation tokens
Source: C Programming Modern Approach Book
Asaduzzaman Herok, Lecturer
03 September, 2024 16
Department of Computer Science and Engineering, IUT
Asaduzzaman Herok, Lecturer
03 September, 2024 17
Department of Computer Science and Engineering, IUT