0% found this document useful (0 votes)
29 views65 pages

Lec 1-1

Uploaded by

nomanashraf9632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views65 pages

Lec 1-1

Uploaded by

nomanashraf9632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 65

Programming Fundamentals

Lecture 1 – Introduction
ENGR. Muhammad Talha Jahangir,
MS(Computer Engineering) NUST, Pakistan
[email protected]

Exam Type Marks


Assignment 5
Quiz 10
No Of Assignment = 2 Mid Term 30
No Of Quiz = 2 Final 40
Project 5
Project Presentation 5
Class Performance 5
About Me
 CEO: JTECH Solutions & Computer Academy, Mumtazabad Multan, Pakistan
 Work Experience
 IRAS, Multan Pakistan
(Visiting Lecturer)
 MNSUA University of Agriculture, Multan Pakistan
(Visiting Lecturer)
 MNS UET MULTAN, Pakistan
(Visiting Lecturer)
 KAIMS International Institute, Multan Pakistan
(Visiting Lecturer)
 University Of Central Punjab, Multan Pakistan
(Visiting Lecturer)
 GWC Networks LLC Dubai
(Network Engineer)
 Pakistan Telecommunication Company Limited (PTCL) Data Centre & Pakistan Internet Exchange (Pie), Lahore Pakistan
(Intern)
 Certifications
 Cisco Certified Network Associate CCNA (Routing & Switching)
 Cisco Certified Network Professional CCNP (Routing & Switching)
 Microsoft Certified Systems Associate (MCSA)
 Microsoft Certified Professional (MCP)
 Microsoft Certified Solutions Expert (MCSE)
 Palo Alto Firewall Accredited Configuration Engineer (ACE (PAN-OS 7.0))
 BLOCKCHAIN Certification
 Cisco Certified Network Associate (Cisco IOS Network Security) & (VOIP)
Professional Education
 MS Computer Engineering, EME NUST RAWALPINDI,PAKISTAN
 BS Computer Engineering, BZU MULTAN,PAKISTAN
Course Outline
• Introduction to problem solving
• A brief review of Von-Neumann architecture
• Introduction to programming, role of compiler and
linker,
• Introduction to algorithms
• Understand the difference between machine level
language and high level language
• History of C / IDE
• Starting to 'C’
• Basic data types and variables
• Input/output constructs
• Arithmetic, comparison and logical operators
Course Outline
• Conditional statements and execution flow for
conditional statements
• Repetitive statements and execution flow for
repetitive statements
• Static Keyword in C
• Lists(Array) and their memory organization, multi-
dimensional lists,
• Introduction to modular programming
• Function definition and calling
• Stack rolling and unrolling,
• String and string operations
• Pointers/references,
• Static and dynamic memory allocation
• File I/O operations
Relevant Books
1. Let Us C (5th Edition) by Yashavant P. Kanetkar
2. The C Programming Language (2nd Edition) by
DENNIS M.RITCHIE
3. C How To Program (6th Edition) by DEITEL &
DEITEL

 Programming Tool: C Language


 C Programming IDE: Visual Studio Code
 Compiler For C (Microsoft OS): MinGW
Expected Outcome
A student who successfully completes the course will have the
ability to:
Understand the basic terminology used in computer programming
Write, compile and debug programs in C language
Use different data types in a computer program
Design programs involving decision structures and loops
Understand Modular Programming (Function)
Explain the difference between call by value and call by reference
Understand the dynamics of memory by the use of pointers.
Use data structures (Array)
Understand String and its Use
Perform file read and write Operations

Understand the given problem and provide the solution in the form of
program
Chapter 1: Introduction
1.1 Introduction
1.2 Computers: Hardware and Software
1.3 Von Neumann Architecture
1.4 Computer Organization
1.5 What is Programming, Skills for programming & its Importance
1.6 Programming Skill Techniques
1.7 Program development process
1.8 Types of Programming Language
1.9 Use of Different programming Language
1.10 Characteristics of High level Language
1.11 Structure & Unstructured Programming Language
1.12 Different Programming Styles
1.13 Getting Starting with C Programming
1.14 History of C
1.15 IDE & Compiler
1.16 Debugging & Program Errors
1.17 Visual Studio Code & MinGW-w64
1.18 Difference between source code and object code
1.19 Steps to prepare C program for execution
1.20 Pons and Cons of C
1.21 Applications of C Programming
Introduction
 As this course is titled “Introduction to programming”,
therefore it is most essential and appropriate to understand
what programming really means.
 When we say that we have a program, it actually mean that we
know about a complete set activities to be performed in a
particular order. The purpose of these activities is to solve a
given problem.
 Practically, in our day to day lives we are constantly planning,
organizing and paying attention to fine details (if we want our
plans to succeed). And it is also fun to do these activities.
 For example, for a picnic trip we plan where to go, what to
wear, what to take for lunch, organize travel details and have a
good time while doing so.
 We also think logically such as, after picnic if we will not tired
than we will go some other place for more enjoy.
Computers: Hardware and Software
 A computer is a versatile electronic device that can perform
computations and make logical decisions billions of times
faster than human beings can.
 Computer is Fast but it is dumb it cannot do any task our
instruction.
 Computers process data under the control of sets of
instructions called computer programs.
 These programs guide the computer through orderly sets
of actions specified by people called computer
programmers.
 A computer consists of various devices referred to as
hardware (e.g., the keyboard, screen, mouse, hard disk,
memory, DVDs and processing units).
 The programs that run on a computer are referred to as
software.
Von Neumann Architecture
 The Von Neumann architecture, also known as the Princeton
architecture, is a computer architecture based on that described
in 1945 by the mathematician and physicist John Von
Neumann.
 He described an architecture for an electronic digital computer
with parts consisting of a processing unit containing an
arithmetic logic unit (ALU) and processor registers, a control
unit containing an instruction register and program counter
(PC), a memory to store both data and instructions, external
mass storage, and input and output mechanisms.
 Von Neumann architecture is composed of three distinct
components (or sub-systems): a central processing unit
(CPU), memory, and input/output (I/O) interfaces.
Von Neumann Architecture Diagram
Computer Organization
 Even now modren Computer Organization based on Von
Neumann Architecture.
 Every computer may be envisioned as divided into six
logical units or sections:

1. Input Unit
2. Output Unit
3. Memory Unit
4. Arithmetic and Logical Unit
5. Central Processing Unit
6. Secondary Storage Unit
Computer Organization Explanation
1. Input Unit: An input device or unit(read information) sends
information to a computer system for processing. It is the
input unit for processor. Humans typically enter information
into computers through keyboards and mouse devices.
Information also can be entered in many other ways, including
by speaking to your computer, scanning images and barcodes,
reading from secondary storage devices (like hard drives, CD
drives, DVD drives and USB drives—also called “thumb
drives”).
2. Output Unit: As we know, an input device or unit sends
information to a computer system for processing. while
output device(write information) or unit reproduces or
displays the results of that processing. Most information that is
output from computers today is displayed on screens, printed
on paper, played on audio players (such as Apple’s popular
iPods), or used to control other devices. Computers also can
output their information to networks, such as the Internet.
Computer Organization Explanation
3. Memory Unit: The computer memory is a temporary storage
area. It holds the data and instructions that the Central
Processing Unit (CPU) needs. The memory unit also retains
processed information until it can be placed on output devices
by the output unit.
 Information in the memory unit is volatile—it’s typically lost
when the computer’s power is turned off.
 The memory unit is often called either memory or primary
memory.
4. Arithmetic and logic unit (ALU): This “manufacturing”
section performs calculations, such as addition, subtraction,
multiplication and division.
 It also contains the decision mechanisms (Logical Unit) that
allow the computer, for example, to compare two items from
the memory unit to determine whether they’re equal.
 In today’s systems, the ALU is usually implemented as part of
the next logical unit, the CPU.
Computer Organization Explanation
5. Central processing unit (CPU): CPU (pronounced as separate letters) is the
abbreviation for central processing unit. Sometimes referred to simply as the central
processor, but more commonly called a processor, the CPU is the brains of the computer
where most calculations take place.
 The CPU tells the input unit when to read information into the memory unit, tells the ALU
when information from the memory unit should be used in calculations and tells the output
unit when to send information from the memory unit to certain output devices.
 Many of today’s computers have multiple CPUs and, hence, can perform many operations
simultaneously—such computers are called multiprocessors.
 A multi-core processor implements multiprocessing on a single integrated circuit chip—for
example a dual-core processor has two CPUs and a quad-core processor has four CPUs.

6. Secondary storage unit: Programs or data not actively being used by the other
units normally are placed on secondary storage devices (e.g., your hard drive) until they’re
again needed, possibly hours, days, months or even years later.
 Therefore, information on secondary storage devices is said to be persistent—it is
preserved even when the computer’s power is turned off.
 Secondary storage information takes much longer to access than information in primary
memory, but the cost per unit of secondary storage is much less than that of primary
memory.
 Examples of secondary storage devices include CDs, DVDs and flash drives (sometimes
called memory sticks), which can hold hundreds of millions to billions of characters.
Programming
 Programming is the process of creating a set of instructions that tell a
computer how to perform a task. Programming can be done using a variety of
computer "languages," such as SQL, Java, Python, and C++.
 "A program is a precise sequence of steps to solve a particular problem.”
 Programming is an art of creativity.
 The only source to become a programmer is practice because programming
learn from doing rather than just knowing conceptual knowledge.
 By designing programs, we learn many skills that are important for all
professions.
 These skills can be summarized as:
o Critical reading (Critical reading involves: carefully considering and
evaluating the reading. identifying the reading's strengths and implications.
identifying
the reading's weaknesses and flaws.(Attention to details))
o Analytical thinking (It involves a methodical step-by-step approach
to thinking that allows you to break down complex problems into single and
manageable components.)
o Creative synthesis (synthesis mean a combination of tow or more entities
that together form something new. Creative synthesis the combination of
several
ideas, images, or associations into a new way which is more clear and able easy
to
7 STEPS TO IMPROVE YOUR ANALYTICAL THINKING
SKILLS
1. Be Observant: Take a walk outside or observe people in your office. Use as many of
your senses, see what’s happening around you. Is there anything that interests you?
2. Read Books: Once again, the key to improving your analytical thinking skill is to
keep your mind active and running.
3. Learn How Things Work: Don’t just find the solution but know how exactly certain
things work.
4. Ask Questions: The more curious we are about a subject, the more it engages our
cognitive functions, such as attention and memory.” With that said, asking more
questions can help develop better problem-solving skills, retention, and memory of a
subject. So don’t be shy to ask questions, especially if your query is valid.
5. Play Brain Games: If you want to improve your analytical thinking skills, it may be
time to play Sudoku or other brain games like puzzles, chess, or crosswords. It helps
to make your brain creative and thinkable.
6. Practice Your Problem Solving Skills: Keep in mind that for every problem, there is
a solution. Visualize and be articulate in the presentation of a particular concept.
Prepare two, three or even more solutions to a problem. And, if possible, do test runs
on those solutions. See which one is the best and the most logical.
7. Think About Your Decisions: Making important decisions at work is very common.
Thus, think hard and rationalize your decisions. What are the pros and cons of your
decision?
What Specifications are needed for program
 Programming is an important activity as people life and
living depends on the programs one make.
 Hence while programming one should:

o Paying attention to detail


o Think about the reusability.
o Think about user interface
o Understand the fact the computers are stupid
o Comment the code liberally
Explanation
 Paying attention to detail: In programming, the details matter. This is a very
important skill. A good programmer always analyzes the problem statement very
carefully and in detail. You should pay attention to all the aspects of the problem.
 Think about the reusability: When ever you are writing a program, always keep
in mind that it could be reused at some other time. Also, try to write in a way that
it can be used to solve some other related problem.
A classic example of this is: Suppose we have to calculate the area of a given
circle. We know the area of a circle is (Pi * r^2). Now we have written a program
which calculates the area of a circle with given radius. At some later time we are
given a problem to find out the area of a ring. The area of the ring can be
calculated by subtracting the area of outer circle from the area of the
inner circle. Hence we can use the program that calculates the area of a circle to
calculate the area of the ring.
Explanation
 Think about Good user Interface: As programmers, we assume that
computer users know a lot of things, this is a big mistake. So never
assume that the user of your program is computer literate. Always
provide an easy to understand and easy to use interface that is self
explanatory.
 Understand the fact that computers are stupid: Computers are
incredibly stupid. They do exactly what you tell them to do: no more,
no less-- unlike human beings. Computers can't think by themselves. In
this sense, they differ from human beings. For example, if someone
asks you, “What is the time?”, “Time please?” or just, “Time?” you
understand anyway that he is asking the time but computer is different.
Instructions to the computer should be explicitly stated. Computer will
tell you the time only if you ask it in the way you have programmed it.
 Comment the code liberally: Always comment the code liberally. The
comment statements do not affect the performance of the program as
these are ignored by the compiler and do not take any memory in the
computer. Comments are used to explain the functioning of the
programs. It helps the other programmers as well as the creator of the
program to understand the code.
Programming Solving Technique
 Problem solving is a process of identifying a problem and finding
the best solution for it.
 Problem solving' is a skill that can be developed by following a well
organized approach.
 We solve different problems every day. Every problem.is different
in its nature.
 Some problems are very difficult and require more attention to
identify the solution.
 A problem may be solved in different ways.
 One solution may be faster, less expensive and more reliable than
others. It is important to select the best suitable solution.
 A person can be good programmer if he has the skill of solving
problems.
Different problem-solving techniques are as follows;
1. Program
2. Algorithm
3. Flowchart etc.
Algorithm
 An algorithm is a step-by-step procedure to solve a problem.
 The process of solving a problem becomes simpler and easier with
help of algorithm.
 It is better to write algorithm before writing the actual computer
program.
Following are some properties of an algorithm:
 The given problem should be broken down into simple and
meaningful steps.
 The steps should be numbered sequentially.
 The steps should be descriptive and written in simple English.
Advantages of an Algorithm
Some advantages of algorithm are as follows:
1. Reduced Complexity
Writing algorithm and program separately simplifies the overall task
by dividing it into two simpler tasks.
While writing the algorithm, we can focus on solving the problem
instead of concentrating on a particular language.
2. Increased Flexibility
Algorithm is written so that the code may be written in any language.
Using the algorithm, the program could be written in Visual Basic,.
Java or C++ etc.
3. Ease of Understanding
It is not necessary to understand a particular programming language to
understand an algorithm. It is written in an English like manner.
Flowchart
 Flowchart is combination of two words flow and chart.
 A chart consists of different symbols to display information about
any program.
 Flow indicates the direction of processing that takes place in the
program.
 Flowchart is a graphical representation of an algorithm. It is a way of
visually presenting the flow of data, operations performed on data
and sequence of these operations.
 Flowchart is similar to the layout plan of a building. A designer
draws the layout plan of the building before constructing it.
 Similarly, a programmer prefers to design the flowchart before
writing the computer program.
 Flowchart is designed according to the defined rules.
Flowchart Symbols
Flowchart Symbols
Flowchart Symbols
Flowchart Symbols
Guidelines for Drawing Flowchart
Guidelines for Drawing Flowchart
Flowchart Example
Use of Flowchart
Flowchart is used for the following reasons:
1. Flowchart is used to represent an algorithm in simple
graphical manner.
2. Flowchart is used to show the steps of an algorithm in an
easy way.
3. Flowchart is used lo understand the flow of the program.
4. Flowchart is used to improve the logic for solving.
Different between Flowchart & Algorithm
Program development Process
A programmer to go through the following stages to develop
a computer program:
1. Defining and Analyzing Problem
2. Designing the Algorithm ·
3. Coding or Writing the Program
4. Testing Program
5. Final Documentation
Types Of Programming Language
 As we know that a program is a set of instructions that
tells a computer what to do in order to come up with a
solution to a particular problem.
 Programs are written using a programming language.
 A programming language is a formal language designed
to communicate instructions to a computer. There are two
major types of programming languages:
1. Low-level languages
2. High-level languages.
 A low-level language is a programming language that
provides little or no abstraction of programming concepts
and is very close to writing actual machine instructions.
Two good examples of low-level languages are assembly
and machine code.
Explanation
 Machine language, or machine code, is the only language that is directly
understood by the computer, and it does not need to be translated. All instructions use
binary notation and are written as a string of 1s and 0s. A program instruction in
machine language may look something like this:
i.e. 10010101100101001111101010011011100101
Technically speaking, this is the only language computer hardware understands.
However, binary notation is very difficult for humans to understand. This is
where assembly languages come in.
 Assembly language is the first step to improve programming structure and make
machine language more readable by humans. An assembly language consists of a set
of symbols and letters. A translator is required to translate the assembly language to
machine language. This translator program is called the 'assembler.' It can be called
the second generation language since it no longer uses 1s and 0s to write instructions
in which machine instruction are represented by English words. These words are
called mnemonics spelled as (Ne-Monic), but terms like MOVE, ADD, SUB and
END.
i.e. ADD D2,D1 ([D1] ← [D1]+[D2] Add contents of D1 to D2 and put sum in D1)
While easier than machine code, assembly languages are still pretty difficult to
understand. This is why high-level languages have been developed.
 High level languages are very much developer/human understandable and these are
the types of languages which are widely famous now. High level language is close to
humans as it is easily understandable by humans but not by computers. Hence tools
like compiler and interpreter are required for its conversion to machine language. i.e.
C, Java, Python, C++, C#, Android
Characteristics of High-Level Language
 All high-level languages have some common characteristics.
Following is a brief description of these characteristics:

1. Machine Independence
2. Can be implemented on a variety of machines
3. Problem Oriented Language
4. Easier to Understand
5. Well defined Syntax and standard
6. Easy to debug

Note: Each high level language has standard Syntax. The standard
is published by several international organizations. An important
organization that publishes the computer programming language
standard is ANSI (American National Standard Institute). The
compilers are written according to the standard syntax of the
language.
Structure & Unstructured Programming Language
 A programming language in which entire program is written as a
single continuous block is called unstructured programming
language.
 Program written in an unstructured language is very difficult to read
and debug.
 Examples of unstructured programming language are JOSS,
FOCAL, MUMPS, TELCOMP, COBOL.
 A programming language in which a program is written by dividing
it into smaller sections or module is called structure
programming language.
 Each module of the program performs a specific function.
 Program written in structure programming language are easy to
write and debug.
 Examples of Structured programming language are C, C+, C++,
C#, Java, PERL, Ruby, PHP, ALGOL, Pascal, PL/I and Ada etc.
Explanation
 Object-oriented programming: Object-Oriented
Programming is a methodology or paradigm to design a
program using classes and objects. Object means a real-
world entity such as a pen, chair, table, computer, watch,
etc. It simplifies software development and maintenance
by providing some concepts:

1. Object
2. Class
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism

Simula is considered the first object-oriented programming


language. Similarly java, C#, C++, Python etc are OOP
language.
Different Programming Style
 Programming styles are like beard styles. People give
names to different styles, but there's a lot of overlap and
grey areas between them.
 The programming styles are: declarative, imperative,
procedural, functional, and object oriented.
 Declarative programming: In a declarative programming
style you describe the results that you want, but not how to
get there. For example sql , Prolog etc.
 Imperative programming: Anything that isn't declarative
can be categorized as imperative. Imperative programming
is a paradigm of computer programming in which the
program describes a sequence of steps that change the
state of the computer. For example C, C++ etc.
Explanation
 Procedural programming: Procedural programming is
imperative programming where you're allowed to write reusable
subs/functions. Pretty much every imperative programming
language allows you to write these now, so it's almost a synonym
for imperative programming. A procedural language is a type of
computer programming language that specifies a series of well-
structured steps and procedures within its programming context to
compose a program. It contains a systematic order of statements,
functions and commands to complete a computational task or
program. In which u have code and also functions in specific way.
 Functional programming: In functional programming
you compose your program of short functions. All code is
within a function. All variables are scoped to the function.
What’s more, within a function, you cannot modify any
variables.
Explanation
 Event-Driven Programming: An event occurs when
something happens. Following are some examples of events:
1. Clicking the mouse button.
2. Typing a character from keyboard.
3. Moving the mouse.
4. Deleting or changing a value.
 Event-driven programming a programming technique in which
statements are executed is in event.
For example:
1. When the user right dicks on a window, a popup menu appears.
2. When the user presses ALT +F4, the current window is closed.
3. When the user clicks on Print button, the file is printed etc.
 In event-driven programming, the programmer write code that is
executed when a particular event occurs.
 Normally, event-driven programming technique is used with visual
programming environment,.
Explanation
 Visual Programming: Visual programming is used to provide a
user-friendly interface for interacting with the program.
 Different objects like windows, menus, buttons and list boxes are
used to develop the graphical user interface.
 Visual programming environment provides all objects as built-in
components to develop a graphical user interface.
 The programmer docs not have to create these objects.
 When the programmer needs a specific object such as a button, he
selects it from the toolbox.
 These components can be moved, resized and renamed as required.
Different Programming languages and its Use
Different Programming languages and its Use

Swift Swift which was introduced in 2014, is Apple


programming language of the future developing iOS and
OS X applications. Swift is now open source, so it can be
used on non-Apple platform as well.
Different Programming languages and its Use
Different Programming languages and its Use
Different Programming languages and its Use

Android Android is a mobile operating system based on a


modified version of the Linux kernel and other open
source software, designed primarily for touchscreen
mobile devices such as smartphones, TV’s and
tablets.
Getting Started With C
 Communicating with a computer involves speaking the language
the computer understands.
 However, there is a close analogy between learning English
language and learning C language.
 C is a high-level structured oriented programming language, used in
general-purpose programming, developed by Dennis Ritchie at
AT&T Bell Labs, the USA between 1969 and 1973.
 The classical method of learning English is to first learn the
alphabets used in the language, then learn to combine these
alphabets to form words, which in turn are combined to form
sentences and sentences are combined to form paragraphs.
 Learning C is similar and easier. Instead of straight-away learning
how to write programs, we must first know what alphabets,
numbers and special symbols are used in C, then how using them
constants, variables and keywords are constructed, and finally how
are these combined to form an instruction.
 A group of instructions would be combined later on to form a
program.
Diagram
History of C
 C evolved from two previous languages, BCPL and B. BCPL was developed
in 1967 by Martin Richards as a language for writing operating-systems
software and compilers.
 The C language was evolved from B by Dennis Ritchie at Bell Laboratories
and was originally implemented on a DEC PDP-11 computer in 1972.
 Different universities researcher work on C and design new C modules, so
language standard committee settle down and think to standardized the C
because each university work on some modules while other used other
modules.
 In 70’s C language standard published named as American national Standard
Institute C (ANSI C).
 C initially became widely known as the development language of the UNIX
operating system.
 Today, virtually all new major operating systems are written in C and/or C++.
 C is available for most computers.
 C is mostly hardware independent.
 With careful design, it’s possible to write C programs that are portable to
most computers.
 In C language we write system as well as system & application Software.
Integrated Development Environment & Compiler
 IDE stands for Integrated Development Environment. It is a
software application that provides facilities for developing software.
It consists of tools such as source code editor, automation tools, and
debugger. IDE
 Most IDEs have compilers and interpreters. Therefore, it is easier to
write the code and compile it. Some IDEs support various
languages.
 For example, in Microsoft Visual Studio IDE, the developer can
write programs in languages such as C#, C++, Visual Basic,
and JavaScript.
IDE contains:
1. Editor
2. Compilers
3. Debugger
4. Linkers
5. Loaders
Integrated Development Environment & Compiler
 Visual Studio Code is a lightweight but powerful source
code editor which runs on your desktop and is available
for Windows, macOS and Linux. It comes with built-in
support for JavaScript, TypeScript and Node.js and has a
rich ecosystem of extensions for other languages (such as
C++, C#, Java, Python, PHP, Go) and runtimes (such
as .NET and Unity). Enable additional languages, themes,
debuggers, commands, and more. It is free and open
source. VS Code's growing community shares their secret
sauce to improve your workflow.
 Compiler is a program that converts instructions into a
machine-code or lower-level form so that they can be read
and executed by a computer.
 Visual Studio Code not contains the compiler of “C”.
Integrated Development Environment & Compiler
 GNU is not a compiler. It is an Operating System and a collection of
free software made to be "Unix like" without using Unix. GNU is
composed wholly of free software, most of which is licensed under
the GNU Project's own General Public License. GNU is a recursive
acronym for "GNU's Not Unix!", chosen because GNU's design
is Unix-like, but differs from Unix by being free software and
containing no Unix code.
 GCC stands for "GNU Compiler Collection" and is a piece of GNU
software that includes a compiler with frontends for multiple
languages: C (gcc), C++ (g++), Objective-C, Objective-C++,
Fortran (gfortran), Java (gcj), Ada (GNAT), and Go (gccgo).
 MinGW stands for "Minimalist GNU for Windows" It is essentially
a tool set that includes some GNU software, including a port of
GCC.
 In summary, MinGW contains GCC which is in the collection of
GNU free software.
Debugging & Program Errors
 Bugs: An error in program is called Bugs.
 Debugging is the process of finding and removing errors from
computer hardware and software.

Types of Error in program

 There are three types of error in a program. These


are:

1. Syntax Error
2. Logical Error
3. Runtime Error
Types of errors in Program
 The rule for writing statements in a computer programming language is
called syntax of the language.
 Syntax Error: A single mistake in these rules causes an error. This error
is called the syntax error.
 The Compiler detects syntax error. It doses not compile a program, that
contains a syntax error. Compiler generally specifies the location and type
of syntax error in a source program. These error are, therefore easy to
locate and remove.
 Example of syntax error include:
1. a missing statement terminator;
2. a misspelled keyword, for example typing mane() instead of main().
 Logical error: The errors in the logic of a program is called logical error.
The compiler cannot detect these error. Debugger is used to remove
logical errors. A program runs with logical error on the computer but
produce wrong results.
 The logical error may occur due to the following reason:
1. Data input is incorrect because the output of the program depend
upon its input data.
2. The sequence of operations in a program may be incorrect.
3. A mathematical formula in a program may be incorrect.
Types of errors in Program
 Runtime error: are the error because they are occur
during the execution of a program.
 Runtime error occur when a program tries to:

1. divided by zero
2. call a function that do not exist.
 The computer stops executing the program when a runtime
error occurs and display the nature of the runtime error.
Difference between Source code and object code
 A computer program written in a high level
language is called the source program. It is also
called source code.
 Computer does not understand the source program.
Source program cannot run directly on the
computers.
 A computer program in a machine language is
called the object program. It is also called object
code.
 Compiler task to convert source code into object
code.
Steps to prepare C program for execution

Editor Disk Program is created in the editor and


stored on disk.

Preprocessor Disk Preprocessor program processes the


code.
Compiler creates object code and
Compiler Disk
stores it on disk.

Linker Disk
Linker links the object code with the
libraries. Linker is used to make
Primary Memory executable file because program need
executable file
Loader

Loader puts program in memory. Loading


Disk ..
is used to run executable file which tells
..
..
the processor, where we execute the first
instruction
Primary Memory

CPU
CPU takes each
instruction and executes it, possibly
storing new data values as the program
..
..
..
executes.
Some Facts About C Programming
 In 1988, the American National Standards Institute
(ANSI) had formalized the C language.
 C was invented to write UNIX operating system.
 C is a successor of 'Basic Combined Programming
Language' (BCPL) called B language.
 Linux OS, PHP, and MySQL are written in C.
 C has been written in assembly language.
 Still, the best programming language to learn
quickly.

Pros and Cons C
Advantages of C
C is the building block for many other programming languages.
Programs written in C are highly portable.
Several standard functions are there (like in-built) that can be used to
develop programs.
C programs are collections of C library functions, and it's also easy to
add functions to the C library.
The modular structure makes code debugging, maintenance, and
testing easier.
C is a fast language.
Pros and Cons C
Disadvantages of C
C does not provide Object Oriented Programming (OOP)
concepts.
There are no concepts of Namespace in C.
C does not provide binding or wrapping up of data in a
single unit.
C does not provide Constructor and Destructor.

C does not provide Object Oriented Programming


(OOP) concepts.
There are no concepts of Namespace in C.
Applications of C Programming
 C was initially used for system development work, particularly the programs that
make-up the operating system. C was adopted as a system development language
because it produces code that runs nearly as fast as the code written in assembly
language. Some examples of the use of C are -

 Operating Systems
 Language Compilers
 Assemblers
 Text Editors
 Print Spoolers
 Network Drivers
 Modern Programs
 Databases
 Language Interpreters
 Utilities

You might also like