You are on page 1of 24

OVERVIEW OF C PROGRAMING

Subject: Programing Fundamentals


Week-1
Teacher: Bilal Munir Mughal
Types of Programming language
2

 Machine Language

 High Level Language

 Special Purpose Language


Machine Language
3

 Machine Language – A collection of very detailed,


cryptic instructions that control the computer’s internal
circuitry.
 Natural dialect of the computer.
 Problems:
 It is very cumbersome to work with.
 Every different type of computer has its own unique instruction
set.
 Example: Assembly Language
High Level Language
4

 High Level Language – Instruction set is more


compatible with human languages and human
thought processes.
 Example: C, Pascal, Fortran
 Advantages:
 A single instruction in high level language is equivalent to several
instructions in machine language.
 Simple Program written in high level
 Uniform language must be translated
 Portable (Machine independent) into machine language before
execution.
Disadvantage : Slow !!!
Compiler and Interpreter
5

 Compiler – Translate the entire program into


machine language before executing any of the
instructions. This process is known is
Compilation.

 Interpreter – Proceed through a program by


translating and then executing single instructions
or small groups of instructions. This process is
known is Interpretation.
Compiler and Interpreter
6

Program written in Machine language


High-level language program
Input Compiler/Interpreter (A Output
computer program)

• The original high-level program is called the Source program.


• The resulting machine-language program is called the Object program.
General Characteristics of C
7

The general characteristics,


 Structured programming language

 Augmented by certain English keyword (e.g. if, else, for)

 It can be used for System programming (e.g. Operating System) and


Application programming (e.g. Software Development)

 Small instruction set

 Extensive library function

 C compilers are available for computer of all sizes

 Highly portable
Structure of C program
8

 Every C program consists of one or more modules called


functions.

 One of the functions must be called main

 Program execution must begin from main function

 Other user defined function must be defined either ahead of


or after main
Composition of a Function
9

 A function must contain,


 A function heading consists of function name, then followed by an optional list of
arguments enclosed in parentheses
 A list of argument declarations
 A compound statement Function Name Argument List

Function
function_name (arg1, ar2 … argn) Heading
{
Statement 1
Statement 2
Compound
return data; Statement
}
Composition of a Function
10

 A function must contain,


 A function heading consists of function mane, then followed by an optional list of
arguments enclosed in parentheses
 A list of argument declarations
 A compound statement

function_name (arg1, ar2 … argn)


{ main( )
Statement 1 {
Statement 2 printf(“Hello”);
return 0;
return data; }
}
Algorithms
11

 A set of steps to accomplish a task


 In Computer Science, an algorithm is a set of steps in a computer
program to accomplish a task

Starts with input data

Do complex calculations

Stop when we find answer


Flowchart
12

 A flowchart is a diagram that
 represents an algorithm  
 represents the workflow or process,
 shows the order of executing the processes.
Flowchart
13
A Sample Program
14

#include<stdio.h>
main()
{
int number = 100;
float sum = 57.26 + 100.1
printf(“%d”,number);
printf(“%.2f”,sum);
}
Variable
15

 A variable is a data name used to store a data value.


 They can be modified during the program.
 All variables must be declared before they can be used.
 Declaration of Variables:
 It tells the compiler what the variable name is.
 It specifies what type of data the variable will hold.
 Format :
data_type var_name;
data_type var_name1, var_name2, var_name3, ………….. ;
A Sample Program
16

#include<stdio.h>
main()
{
int number; Type declarations
Assigning value
number = 100;
float sum = 57.26 + 100.1
printf(“%d”,number);
printf(“%.2f”,sum);
}
Identifiers
17

Refers to the name of variables, functions, arrays.

 Must start with letter or ‘_’.


 In an identifier, middle characters are letter, digits, or
underscore( ‘_’).
 Must not match with keywords.
 Maximum 31 characters.
 In an identifier, upper & lowercase are treated as distinct. Ex. count,
Count & COUNT are three separate identifiers.
18
CKeyword
Keywords
• have specific meanings
• cannot be changed

C has 32 keywords

Keywords
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
Data
Data Type
Types
19

Type Characteristics Typical Minimal Range Examples


size in
Bytes
int Numeric / integer 2 Byte -32,768 to 32,767 10, -101, 15

float Fractional numbers 4 Byte 1E-37 to 1E+37 with 6 10.568960


digits of precision.
double Fractional numbers 8 Byte 1E-37 to 1E+37 with 11.578965891
10 digits of precision. 2
char Individual letters , 1 Byte -128 to 127 A, Y
symbols, digits.
void No data type
Format
Format Specifier
Specifier
20

Data Type Format Specifier Use


int %d To input/output Integer value
float %f To input/output Fractional
(float) value
double %lf To input/output Fractional
(double) value
char %c To input/output character
Backslash Character Constant/
quences
Escape Sequence
21

Code Meaning
\n New Line
\b Back Space
\t Horizontal Tab
\v Vertical Tab
\0 NULL
\” Double quote
\’ Single quote
\\ Backslash
\a Alert
\? Question mark
scanf()
22

 giving values to variables through keyboard.


variable name’s address

scanf(“control string”,&variable1,&variable2,…);
format specifier of data being received

scanf(“%d”,&variable);
Reference
23

 Programming with C
 Chapter 1 : 1.4, 1.5(Introduction to C, Structure of a C Program)
 Chapter 2 : 2.1, 2.2, 2.3, 2.4, 2.5(Variables), 2.6, 2.7, 2.8, 2.9
24

Q&A

You might also like