This document discusses the execution process of a C program. It begins with preprocessing, where header files are included and macros are replaced. Next is compilation, where the source code is compiled into assembly code, then object code. Linking then combines the object code with library files to create an executable file. The executable file is then loaded into memory and executed, running the program. Translators, compilers, linkers, loaders, and editors are involved in this execution process to generate and run a C program.
2. At a Glance
• Generation of Programming Languages
• Programming Paradigms
• Structure & Execution Environment of a Basic C Program
• Need of Translators, Linkers, Locaters, Loaders & Editors
• Software Engineering & Problem Solving Methods
• Few Inclusions from C99 and C11 Standards
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
2 of 74
4. Generations
• Generation -1: Machine Level Programming Languages (late
1940s)
• Generation -2: Assembly Languages (early 1950s)
• Generation -3: High-Level Languages (mid 1950s to present)
• Generation -4: Specification/Query Language, Report
Generators (1970s to present)
• Generation -5: Artificial Intelligence
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
4 of 74
5. Features of Languages (1/2)
• Machine Level Language
– Fast and efficient, executed directly on the CPU
– Consists only of 0s and 1s
– Difficult for humans to read, write, and debug
• Assembly Language
– Also included Interpreting Routines & early Compilers
– Simple mnemonic instructions <opcode> <operands>
– Assembler translates into machine code
– Hand coding in assembly only for low-level needs
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
5 of 74
6. Features of Languages (2/2)
• High Level Languages
– Easier for humans to read, write, debug
– Compiler translates into machine code before running
– Interpreter translates into machine code at runtime
– Examples: FORTRAN, LISP, COBOL, ALGOL (Ada, Basic, C, C++,
Java, Pascal, Smalltalk, …)
• Fourth Generation
– Examples: Maple, Mathematica, Postscript, SPSS, SQL
• Fifth Generation
– Examples: Prolog
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
6 of 74
7. Family Tree of Languages
01-Sep-2017
Fortran
BASIC
Cobol
LISP
Scheme
ML
Prolog
PL/1
Algol 60
Algol 68
Pascal
Modula 3
Ada
C
C++
Simula
Smalltalk
Java
Dylan
Ruby
Perl
PythonC#
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
7 of 74
9. Procedural Paradigm
• Procedures, sequential execution of code are basic building
blocks of program.
• Examples
– FORTRAN (FORmula TRANslating; John Backus, IBM, 1950s)
– ALGOL (ALGOrithmic Language, 1958)
– COBOL (COmmon Business Oriented Language, 1960)
– BASIC (Beginner's All-purpose Symbolic Instruction Code, John
Kemeny and Thomas Kurtz, Dartmouth, 1963)
– Pascal (Niklaus Wirth, 1970)
– C (Dennis Ritchie, Bell Labs, 1972)
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
9 of 74
10. Object Oriented Paradigm
• Program is designed around the objects and classes required
to solve the problem.
• Examples
– Smalltalk (Alan Kay, Xerox PARC, 1971)
– Ada (US Dept of Defense, 1975)
– C++ (Bjarne Stroustrup, Bell Labs, 1983)
– Java (James Gosling, Sun Microsystems, 1995)
– C# (Microsoft, 2000)
01-Sep-2017
Alan Kay
B. Stroustrup J. Gosling
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
10 of 74
11. Functional Paradigm
• Program is designed around the evaluation of functions,
rather than modifying state
• Examples
– LISP (John McCarthy, MIT, 1958)
– Common Lisp
– Dylan
– Logo
– Scheme
– ML (Robin Milner et al, Edinburgh, 1970s)
– Haskell (purely functional language, 1990)
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
11 of 74
12. Logic & Scripting Paradigms
• Logic
– Program is declarative, based on mathematical logic
– Example: Prolog (1972)
• Scripting
– Used for text processing, shells, HTML, CGI
– Examples
• awk (Aho, Weinberger, Kerningham, Bell labs, 1978)
• Perl (Larry Wall, NASA, 1987)
• Tcl/Tk (John Ousterhout, 1988)
• Python (Guido van Rossum, CWI, 1991)
• PHP (Rasmus Lerdorf, 1995)
• Ruby (Yukihiro Matsumoto, 1996)
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
12 of 74
15. History of C Language
• Kenneth Thompson and Dennis Ritchie at Bell Labs in 1972
• History
– International Group, ALGOL (1960)
– Martin Richards, BCPL (1967)
– Ken Thompson, B (1970)
– Dennis Ritchie, Traditional C (1972)
– Kernighan & Ritchie, K&R C (1978)
– Standardization (incompatible code of different compilers)
• In 1983, ANSI (American National Standard Institute) started
defining a standard for C called ANSI-C. ANSI-C was adopted by
ISO in 1990 renamed to C89 (Officially ANSI/ISO 9989:1990)
• C99 (Officially ISO/IEC 9899:1999)
• C11 (Officially ISO/IEC 9899:2011)
01-Sep-2017
Brian Kernighan and D. Ritchie
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
15 of 74
16. C Language
• High Level Procedural Language
• Features
– Coded routines of UNIX OS
– Concise syntax
– Programs a Efficient and Fast
– Highly portable
– Case-sensitive
– No built-in operations for handling composite data types such
as strings, sets, and lists
• Suited for writing both System software and Business
packages (E.g. C Compilers)
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
16 of 74
17. Basic Structure of C Program
Documentation Section (Comments)
Link Section (Link functions from System Library)
Definition Section (Define Symbolic Constants)
Global Declaration Section (Global Variables & User Defined Fn.)
main() Function Section
{
Declaration Part
Executable Part
}
Subprogram Section
User-Defined Functions
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
17 of 74
18. Sample C Program
• Problem: Sum of two Numbers
//my first program to explain the structure
#include <stdio.h> //preprocessor directive
void main() //Program Entry: main() fn.
{ //Start of Program
int a, b, sum; //declaration of variables
printf(“Enter value of a & b: ”); //Output: printf() built-in fn.
scanf(“%d %d”, &a, &b); //Input: scanf() built-in fn.
sum = a + b; //Arithmetic expression/stmt.
printf(“Sum: %d”, sum);
} //End of Program
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
18 of 74
19. Preprocessor Directives
• Provides instruction to the compiler before the actual program
execution begins
• Hash symbol (#)
• Types (partial list)
– # include <headerfile.h>
• Specify header file which holds prototype definition of built-in
functions. Compiler informs linker to link these files with program
• Example: #include <stdio.h>
– “stdio.h” contains prototype definition of printf() and scanf()
– # define const_name const_value
• Defines Symbolic constants
• Example: # define PI 3.14
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
19 of 74
20. Function Definition
• Definition: Function/Procedure/Sub-routine
– Set of Instructions that are executed to achieve a particular
task
– Code reusability
• Types
– Built-in Functions (System Defined)
• E.g. printf(), scanf()
– User-defined Functions
• Syntax
return_type function_name(Argument list)
{ //fn. Definition starts
Set of Instructions //fn. body
} //fn. Definition ends
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
20 of 74
21. Program Input
• scanf() function
– Input from Standard Input
– Prototype definition available in stdio.h
• E.g. scanf(“%d %d”, &a, &b);
– Format String
• Specifies the expected data type format of the input variables
using corresponding format specifiers
– Address-of Operator (&)
• Provides the memory address of the input variable were the
input value is to be stored
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
21 of 74
22. Program Output
• printf() function
– Output to Standard Output
– Prototype definition available in stdio.h
– Format
• Print a String
– E.g. printf(“Hello”); //Output String “Hello”
• Print a value within a String
– E.g. printf(“Sum: %d”, sum); //Value of sum is printed with String
– Format specifier (E.g. %d)
» Specifies the expected data type format of the output variable
whose value is to be printed within the Output String
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
22 of 74
23. Format Specifiers in C (1/2)
Format Specifier printf() scanf()
%c Prints a single character Read a character
%d Prints a signed decimal integer Read a signed decimal integer
%i
Prints a signed decimal
integer
Read a signed integer depending
upon the prefix
- a hexadecimal integer if prefix
is 0x
- a signed octal if prefix is 0
- if no prefix read signed decimal
integer
%u
Prints an unsigned decimal
integer
Unsigned decimal integer
%o Prints an unsigned octal integer Unsigned octal integer
%x
Prints an unsigned hexadecimal
using a,b,c,d,e,f
Read unsigned hexadecimal integer
%X
Prints an unsigned hexadecimal
using A,B,C,D,E,F
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
23 of 74
24. Format Specifiers in C (2/2)
Format Specifier printf() scanf()
%f
A floating point with 6 digits after
decimal point
Read floating point number
%e
Floating point in exponential
format with e
Read floating point number
%E
Floating point in exponential
format with E
%g
Float in %f or %e whichever is
shorter
Floating point number
%G
Float in %f or %E whichever is
shorter
%s String Read a string (till null character)
%% Prints % sign Not applicable
%p
Prints address in hexadecimal
format
Not applicable
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
24 of 74
25. Program Execution (1/7)
01-Sep-2017
Preprocessing
Program Compilation
Linking
Locating
• Steps involved
Loading
Program Execution
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
Program Creation
Source Code (*.c)
Expanded Source Code (*.i)
Object Code
Executable Object Code
Assembly Code
25 of 74
26. Program Execution (2/7)
• Preprocessor Stage
– The following occurs to the Source code
• Header Files are expanded
• Comments are removed
• Macros are replaced
– To print the expanded code on terminal after preprocessing,
the command in Linux is
• $cc -E file_name.c
– To obtain the expanded code in a file the command in Linux is
• $cc -E file_name.c -o file_name.i
– After above said command is executed, a file “file_name.i” is
generated in present working directory and whole code obtained
after pre-processing stage is stored in this file. This file can be
opened for viewing the whole content.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
26 of 74
27. Program Execution (3/7)
• Compilation Stage
– Considered to include (1) Compiler Stage & (2) Assembler Stage
• Compiler Stage
– At compilation stage an assembly code (with .s as extension) is
generated on the basis of Source code i.e. depending upon the
functions and structures used in the C program.
– To obtain the assembly code the foll. commands can be used
• $cc –S file_name.c OR $cc –S file_name.i
• Note: Assembler accept files with .i or .c extension
– The obtained file name can be specified as follows:
• $cc –S file_name.i -o file_name.s
– Note: The contents of .s file are not understandable but can be
viewed
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
27 of 74
28. Program Execution (4/7)
• Assembler Stage
– Assembler converts the assembly code to an object code
(machine code) with .obj(windows) or .o(Linux) extension.
– The commands are
• $cc –c file_name.c or $cc –c file_name.i or $cc -c file_name.s
– The obtained file name can be specified as follows:
• $cc –c file_name.s –o file_name.o
– Note: The contents of object file are not understandable but
can be viewed
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
28 of 74
30. Program Execution (6/7)
• Linker Stage
– At linker stage other object files (E.g. Library Files) are linked
and an executable file with .exe(windows) or a.out(Linux) is
generated.
• Library files are pre-compiled files which can be directly linked
– Command
• $gcc file_name.c
– Note:
• Executing above command generates a file with name a.out
which is the executable format of last compiled c-program.
• Every time a new file is compiled the a.out is replaced with new
executable file
• To retain the executable content, the obtained file name can be
specified as follows $ gcc file_name.c -o file_name
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
30 of 74
31. Program Execution (7/7)
• To run the executable place ./ preceding to file_name
– $./a.out or $./file_name
• Note
– To get all the files in one shot the following command can be
used
• $gcc –save-temps file_name.c -o file_name
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
31 of 74
32. Program Execution & Errors
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
32 of 74
34. Editor
• Software used to create and modify source programs
– Has commands that change, delete or insert lines/characters
• Available with Assembly Language programming and High
level language programming
• Example
– Linux OS: vi, gedit, nano, pico, vim
– Windows OS: notepad
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
34 of 74
35. Translators
• Software that translates the user program into the machine
readable/understandable program
• Types
– Assemblers
– Compilers
– Interpreters
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
35 of 74
36. Assembler
• Software that translates Assembly language program into
Machine language program
• Reads the source program more than once
• Creates two files after translation
– Object File (Binary code of Instruction & Information about
Instruction Addresses)
– Assembler List File (Assembly language statements, Binary
code for each Instruction & Offset for each instruction)
• Types
– Self/Resident Assembler & Cross Assembler
– One-pass & Two-pass Assembler
– Meta Assembler
– Macro Assembler
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
36 of 74
37. Compiler (1/6)
• Software that translates High level language program into
Machine language program
• Compiler goes through the entire program – then translates
the entire program into machine codes
• Types
– Self or Resident Compiler
– Cross Compiler
• Vs. Assembler
– A compiler is more intelligent – It checks all kinds of limits,
ranges, errors etc.
– Program run time is more & It has slow speed01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
37 of 74
38. Compiler (2/6)
Steps involved during
Compilation
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
38 of 74
39. Compiler (3/6)
• Lexical Analysis or Tokenizer
– Produces Tokens from Source Code, Symbol Table and Literal
Table
• E.g. Seeing a variable, the tokenizer would generate the token
“var” and then associate the variable name (lexeme) with it in
the symbol table.
– Removes whitespace and comments.
– Handles compiler directives (i.e., as a preprocessor).
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
39 of 74
40. Compiler (4/6)
• Syntactic Analysis
– Tokens are parsed to produce Parse Tree while checking that
tokens conform with the rules of the language.
– Note: Parse trees are often converted into a simplified form
known as a Syntax tree.
• E.g. Consider expression 3+4*5
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
40 of 74
41. Compiler (5/6)
• Syntactic Analysis
– Tokens are parsed to produce Parse Tree while checking that
tokens conform with the rules of the language.
– Note:
• Parse trees are often converted into a simplified form known as a
Syntax tree.
• Semantic Analysis
– Produces Annotated Tree from Syntax tree.
– In addition to this, a literal table (contains information on the
strings and constants used in the program), and a symbol table
(stores information on the identifiers used in the program) are
produced by the various stages of the process.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
41 of 74
42. Compiler (6/6)
• Intermediate Code Generator & Code Optimizer
– Intermediate code generator receives input from semantic
analyzer in the form of an annotated syntax tree.
– Need of Intermediate Code Generator instead of direct
translation into target machine code?
• Intermediate code eliminates the need of a new full compiler for
every unique machine by keeping the analysis portion same for
all the compilers. The second part of compiler, synthesis, is
changed according to the target machine. It is easier to apply the
source code modifications to improve code performance by
applying code optimization techniques on the intermediate code.
• Note: Intermediate code can be either language specific or
language independent.
• Error handler
– Catch errors generated by any stages of the program.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
42 of 74
43. Interpreter
• Software that translates High level language program into
Machine language program (same as Compiler)
• Vs. Compiler
– Translates only one statement of the program at a time and
executes it. In this way it proceeds further till all the
statements are translated and executed
– A compiler is 5 to 25 times faster than an interpreter
– Compiler saves the machine codes permanently for future
reference. Interpreter does not save the machine codes
– An interpreter is a small program as compared to compiler. It
occupies less memory space, so it can be used in a smaller
system which has limited memory space
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
43 of 74
45. Linker
• Software that links built-in functions to the System libraries
& user-defined functions to the User-defined libraries
– If linker does not find a library of a function then it informs to
compiler and then compiler generates an error
• Linker is used to combine the program modules for program
execution
– Modules: Smaller subprograms that together make a longer
program
• Compiler automatically invokes linker as the last step in
program compilation
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
45 of 74
46. Locator
• Software that assigns specific addresses at which the
Executable Object code should be loaded in the System
Memory
• Example
– IBM-PC DOS has a locator called EXE2BIN
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
46 of 74
47. Loader
• Software that loads machine codes (executable object code)
of a program into the system memory and prepares them for
execution
– i.e. Reads contents of executable file into memory
• Integral part of Operating System (OS)
– Once loading is complete, the OS starts the program by passing
control to the loaded program code
– In many OS, the loader is permanently resident in memory
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
47 of 74
49. Software Engineering
• Definition
• Need of Paradigms
• Types
– Classical Life Cycle Model or Waterfall Model
– Iterative Model
– Rapid Application Development Model (RAD)
– Prototyping Model
– Spiral Model
– V Model
• CASE Tools
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
49 of 74
51. Software Development Life Cycle (SDLC)
• (1) Problem Statement
• (2) Requirement Gathering & Analysis
• (3) Propose Solution & Select an best feasible solution
• (4) Design
– Problem solving methods (Flow Chart, Algorithm, Pseudo Code)
• (5) Test the Design: If Test fails – Repeat from Step(4)
• (6) Coding
– Choice of Programming Lang. Paradigm – Language Selection
• (7) Test the Code: If Test fails – Repeat from Step(6)
• (8) Deployment
• (9) Maintenance
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
51 of 74
57. Program Execution using Flow Chart (1/2)
01-Sep-2017
System Ready
Enter ProgramProgram Code
Edit Source Program
Compile Source
Program
C Compiler
Syntax
Errors?
A
Source Program
Object Code
B
Logic Error
Syntax Error
No Errors
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
57 of 74
58. Program Execution using Flow Chart (2/2)
01-Sep-2017 Stop
System Library
Link with System
Library
Execute Object Code
Input
Data
Correct
Output
Logic &
Data
Errors?
Object Code
A
Executable Object Code
No Errors
Data Error
B
Logic Error
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
58 of 74
59. Algorithm
• Algorithm
– Set of operations to be performed Step-by-step.
– Written in natural language.
– Starting from an initial state and initial input the instructions
describe a computation that, when executed, proceeds
through a finite number of well-defined successive states,
eventually producing "output" and terminating at a final
ending state.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
59 of 74
60. Example - 1
• Problem: Snakes and Ladders Game
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
60 of 74
61. 01-Sep-2017
Problem: Snakes and Ladders Game
Flow Chart
CSEG1001/1002
Instructor: Mr.S.Christalin
Nelson|SoCSE|UPES
61 of 74
62. Example – 1 (contd.)
• Problem: Snakes and Ladders Game
– Algorithm
• (1) Game begins
• (2) Roll the dice
• (3) Move ahead as many steps as the number on the dice
– Is there a ladder? If YES, climb it & goto step 5. If NO goto step 4
• (4) Is there a snake?
– If YES, go down & goto step 6
– If NO, remain where your are & goto step 5
• (5) Have you reached End?
– If YES, You have won the game. Goto step 7
– If NO, goto step 6
• (6) Next player's turn – goto step 2
• (7) Game Over
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
62 of 74
63. Example - 2
• Problem: Find Sum of two Numbers
– Algorithm
• (1) Start Operation
• (2) Declare integer variable A, B, Sum
• (3) Read two numbers A, B
• (4) Find Sum = A+B
• (5) Print Sum
• (6) End Operation
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
63 of 74
64. 01-Sep-2017
Problem: Finding sum of two numbers
Flow Chart Testing the Flow Chart
CSEG1001/1002
Instructor: Mr.S.Christalin
Nelson|SoCSE|UPES
64 of 74
65. Pseudocode
• Written in a format that is closely related to high level
programming language structures.
• Uses syntax common to many programming languages.
– These include standard looping structures like FOR … ENDFOR,
WHILE…ENDWHILE
– There are also some terms for standard conditional clauses like
IF-THEN … ENDIF, WHILE … ENDWHILE (this is both a loop and
a conditional clause by the way), CASE … ENDCASE
• Transforming pseudocode to programming code could be
much easier than converting an algorithm written in natural
language.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
65 of 74
66. Example
• Problem: Accept two numbers from the keyboard and
calculate the sum and product.
– Pseudocode
• Use variables sum, product, number1, number2 of type real
• Display “Input two numbers”
• Accept number1, number2
• sum = number1 + number2
• Print “The sum is “, sum
• product = number1 * number2
• Print “The Product is “, product
• End program
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
66 of 74
67. Program Control Flow
• Order of Execution of Instructions
• Types
– Sequence (Default: Top to Bottom)
– Loop
• Iteration & Recursion
– Branching
• Conditional & Un-Conditional Branching or Jump
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
67 of 74
68. Activity-3
• Solve the following problems with a suitable formulae/logic
and provide the design using Algorithm and Flow chart.
– (1) Find the maximum of three numbers.
– (2) Find area and circumference of a Circle.
– (3) Convert temperature into Centigrade/Fahrenheit/Kelvin.
– (4) Find Simple Interest.
– (5) Swap two numbers with/without using third variable.
– (6) Find the given number is Even or Odd.
– (7) Find the given number is Prime number or not.
– (8) Check whether the given year is Leap year or not.
– (9) Multiply two numbers without using *operator.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
68 of 74
69. Tips to Solve Activity-3
• Area = π x radius2 Circumference = π x d (d = 2r)
• °F = °C x (9/5) + 32, °C = (°F - 32) x (5/9), K = °C + 273.15
• Simple Interest = Principal x Duration x Interest Rate
• Swapping using temporary variable
– temp = a; a = b; b = temp;
• Swapping without temporary variable
– Method 1: x = x + y; y = x - y; x = x - y;
– Method 2: x = x * y; y = x / y; x = x / y;
– Method 3: x = x ^ y; y = x ^ y; x = x ^ y;
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
69 of 74
71. Some Inclusions from C99
• Variables can be defined anywhere inside the function block
• New Data Types
– Boolean data type “bool” used with “stdbool.h” and “_Bool”
• Constants: “true” and “false”.
• Boolean values still behave as integers (Can be stored in integer
variables, and used anywhere integers would be valid)
– Complex data type “complex” used with “complex.h”
• Functions: creal(), cimag(), conj()
• Support to “static inline” functions
• Universal character names allows user variables to contain
other characters than the standard character set which is its
Unicode value in the form: uXXXX or UXXXXXXXX
– XXXX or XXXXXXXX - Unicode code point in hexadecimal notation
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
71 of 74
72. Inclusions from C11
• Use of Anonymous Structure and Anonymous Union when
nested inside another structure.
– i.e. Structure/Union without an Identifier
• Caution with usage of gets(), deprecated in the previous C
language standard revision, ISO/IEC 9899:1999/Cor.3:2007(E)
– Using gets() may lead to buffer overflow. Hence, fgets() and
gets_s() are preferred.
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
72 of 74
73. Peep into the next Module
• Programming using C Language - I
– Programming Fundamentals
– Literals & Variables
– Data Types & Modifiers
– Qualifiers & Constants
– Storage Class Specifiers
– Operators & Expressions
– Data Type Conversions
– Loops & Decision Making
01-Sep-2017
CSEG1001/1002
Instructor: Mr.S.Christalin Nelson|SoCSE|UPES
73 of 74