0% found this document useful (0 votes)
2 views

Lec. Introduction

The document outlines a programming fundamentals course led by Dr. Muhammad Saleem Vighio, covering course structure, programming language concepts, and C programming basics. It includes details on assessments, recommended textbooks, practical exercises, and important instructions for students. Key topics discussed include types of programming languages, the structure of C programs, and the use of the printf() function with format specifiers.

Uploaded by

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

Lec. Introduction

The document outlines a programming fundamentals course led by Dr. Muhammad Saleem Vighio, covering course structure, programming language concepts, and C programming basics. It includes details on assessments, recommended textbooks, practical exercises, and important instructions for students. Key topics discussed include types of programming languages, the structure of C programs, and the use of the printf() function with format specifiers.

Uploaded by

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

Programming Fundamentals

Dr. Muhammad Saleem Vighio (PhD Denmark)


Chairman & Professor,
Department of Computer Science,
Quaid-e-Awam University of Engineering, Science,
& Technology, Nawabshah

Lecture – 01 and 02
Dated: 21-01-2025
1
Outline

• Course introduction
• Programming languages concepts
• C Programming Basics

2
Course Introduction

3
Course Introduction
• Course CHs:
– 03 CHs (42 lectures) :
• Theoretical work
Maximum Marks 100
Tests 05
Assignments 05
Mid Semester Examination 20
Final Semester Examination 60

– 1CHs (42 lectures) :


• Practical work
Maximum Marks 50
Lab Evaluation Work 20

Semester Lab Examination 30


4
Course Introduction
• Recommended Textbook:
– Turbo C Programming for the PC
» Robert Lafore

• Reference Books:
– Let Us C, Latest Edition
» Yashavant P. Kanetkar
– A Book On C
» Al Kelley and Ira Pohl

• Online Literature/Tutorials etc.


5
Course Introduction
• Recommended Tool:
– DevC++

• Practical: SD Lab
– Class exercises and lab tasks

6
Course Introduction
• Teaching plan:
– 02 tests:
• Each after 20TH and 35TH lectures
– Assignments
• At the end of each book chapter (Robert Lafore)
• Assignments are to be collected 1 week after 42nd lecture

– Practical exercises:
• Almost in each practical
• Maintenance of practical

• C project 7
Course Introduction
• C projects
– ATM
– Marks Certificate
– Traffic Control System
– Simple Games
–…

8
Course Introduction
• Lecture slides/announcements/results can be
found at course home page:
http://saleem.quest.edu.pk/

https://sites.google.com/a/quest.edu.pk/saleem

9
Important Instructions
• During the class:
– Keep silent
– Turn off mobile phones
– No attendance for late comers

10
Programming Languages Concept

11
Programming Languages Concepts
• What is a programming language?

• Why do we need programming languages?

• What are the types of programming languages?

12
Programming Languages Concepts
• What is a programming language?

– A programming language is a set of rules that provides


a way of telling a computer how and what operations
to perform.

13
Programming Languages Concepts
• What is a programming language?

– The description of a programming language is usually


split into the two components of syntax (form) and
semantics (meaning).

– A program can execute only if it is both syntactically


and semantically correct.

14
Programming Languages Concepts
• Why do we need programming languages?
– Facilitate users in performing tasks which are:
1. Faster,
2. Correct, and
3. Economically cheaper

15
Programming Languages Concepts
3. What are the types of programming language?

– Programming languages may be divided into three (03)


general types:
1. Machine languages
2. Assembly languages
3. High-level languages

16
Programming Languages Concepts
• Machine languages
– Strings of 0’s and 1’s telling computers to perform
basic operations one at a time; e.g.:
01001110
00111001
01101010
– Machine dependent i.e., a code written for one
machine may not run on the other.
– Programming in machine languages is too slow,
tedious, and error-prone.
17
Programming Languages Concepts
• Assembly languages
– Symbolic operation codes replaced binary operation
codes; e.g.:
LOAD R1, sessional
LOAD R2, final
ADD R1, R2
STORE total_marks
– Assembly language programs need to be “assembled” for
execution by the computer. Each assembly language
instruction is translated into one machine language
instruction.
– Very efficient code and easier to write.
18
Programming Languages Concepts
• High-level languages
– Closer to English but included simple mathematical
notation; e.g.:
total_marks = sessional + final
– Programs written in source code which must be
translated into machine language programs called
object code.
– The translation of source code to object code is
accomplished by a machine language system program
called a “compiler”.
19
Broad Categories of Programming
Languages
• Programming languages may be divided into two
(02) broad categories:

– Traditional/Procedural programming languages


» C, BASIC, PASCAL, PYTHON etc.

– Object-oriented programming languages


» C++, C#, JAVA, CURL etc.

20
C Programming Basics

21
C Programming
• C is a programming language
developed at AT & T’s Bell
Laboratories of USA in 1972.
• The inventor of the C language
is Dennis Ritchie.
• C language is reliable, simple
and easy to use.
• Using C, one can develop
programs for mobile phones,
microwave ovens, 3D games,
and so on.
22
Getting Started
#include <stdio.h> Pre-processor
directive
#include <conio.h>
Function return type
main function

int main(void) Semicolon refers to


string constant the end of statement
{
printf(“This is my first program in C”);
Program body
getch(); getch function that keeps
output visible on screen
}

28
The Basic Structure of C Program
• Function Definition
• Delimiter
• Statement Terminator
• The printf() function
• Preprocessor Directive

29
The Basic Structure of C Program
• Function Definition
– All C Language programs are divided into units called
"Functions".
– A function in C has ( ) at its end. main( ) is always be
the first function to be executed and is the one to
which control is passed when the program is
executed.
– The word “int“ preceding the "main" specifies that
the function return type. The second "void", in the
parenthesis, specifies that the function takes no
arguments.

30
The Basic Structure of C Program
• Delimiter
– Following the function definition are the braces,
which signals the beginning and end of the body of
the function.
– The opening brace " { " indicates that a block of code
that forms a distinct unit is about to begin.
– The closing brace " } " terminates the block code.

31
The Basic Structure of C Program
• Statement Terminator
– The line in our program that begins with the word
"printf " is an example of a statement.
– A statement in C Language is terminated with a
semicolon " ; ".
– The C Language pays no attention to any of the
"White Space Character": the carriage return
(newline), the spacebar and the tab key.
– You can put as many or as few white spaces
characters in your program as you like; since they are
invisible to the compiler.

32
The Basic Structure of C Program
• The printf ( ) function
– The program line printf ("This is my first program in C
Language."); causes the phrase in quotes to be
printed on the screen.
– The word printf is actually a function, just as " main "
is a function name. Since "printf" is a function name,
therefore it is followed by parenthesis.

33
The Basic Structure of C Program
• The printf ( ) function
– The DevC++ linker looks in the stdio.h file of INCLUDE
directory, finds the section of this file containing
printf( ) and causes this section to be linked with the
source program.
– C Language distinguishes between uppercase and
lowercase letters i.e., C language is case sensitive.
– Thus the function PRINTF( ) and Printf( ) are not the
same as the function printf( ).

34
Pre-processor Directives
Pre-processor directive header/include file

#include <stdio.h>
#include <conio.h>

• Program instruction (which end with semicolon) are


instructions to the computer to do something; pre-processor
directives are instruction to the compiler.
• A part of the compiler called the pre-processor deals with
these directives before it begins the real compilation process.
• #include tells the compiler to insert another file into your
source file.
• The type file included by #include is called a header/include file
35
Exploring the printf() Function
• The printf ( ) function
– The printf() function uses a unique format for printing
constants and variables. For example

void main(void)
{
printf("I am %d years old", 20);
}

36
Exploring the printf() Function
• The printf ( ) function
– The printf() function uses a unique format for printing
constants and variables. For example

void main(void)
{
printf("I am %d years old", 20);
}

▪ Output:
I am 20 years old
37
Exploring the printf() Function

• The function printf() can be given more than one


argument. For example in the above program we
have taken 2 arguments in the printf() function.
• The two arguments are separated by a comma.
• The printf() function takes the vales on the right
of the comma and plugs it into the string on the
left.

38
Format Specifiers

• The format specifier tells the printf() where to put


avalue in a string and what format to use in
printing the values.
– In the previous program, the %d tells the printf() to
print the value 20 as a decimal integer.

39
List of Format Specifiers for printf()

40
Using Format Specifiers in printf()

41
Using Format Specifiers in printf()

42
Using Format Specifiers in printf()
void main(void)
{
printf("The letter %c is ", 'j');
printf("pronounced as %s", 'jay');
}

43
Using Format Specifiers in printf()
void main(void)
{
printf("The letter %c is ", 'j');
printf("pronounced as %s", 'jay');
}

▪ Output:
The letter j is pronounced as jay

44
Using Format Specifiers in printf()
• In the above program, there are two new
things to note:
– First we have used %c for printing a character
which is surrounded by single quotes and %s is
used for printing a string which is surrounded by
double quotes.
– This is how C language differentiates between a
character and a string.

45
Using Format Specifiers in printf()
• Second thing to note is that even though the
output statement is printed by two separate
program lines, it does not consist of two line
of text on the out put screen. That is because
printf() does not automatically prints a
newline character at the end of the line.
• So what to do for inserting a newline in a
printf() statement?

46
Using Format Specifiers in printf()
• Second thing to note is that even though the
output statement is printed by two separate
program lines, it does not consist of two line
of text on the out put screen. That is because
printf() does not automatically prints a
newline character at the end of the line.
• So what to do for inserting a newline in a
printf() statement?

47
Using Format Specifiers in printf()
void main(void)
{
printf("The letter %c is \n", 'j');
printf("pronounced as %s", 'jay');
}

48
Using Format Specifiers in printf()
void main(void)
{
printf("The letter %c is \n", 'j');
printf("pronounced as %s", 'jay');
}

▪ Output:
The letter j is
pronounced as jay

49
Using Format Specifiers in printf()
• The above example includes a new symbol,
the ' \n '.
• In C this means "newline ". The ' \n ' has the
effect of a carriage return and linefeed i.e.,
following ' \n ' character, printing is resumed
at the beginning of the next line.

50
Escape Sequences
• Escape sequences allow to control the output of the program

51

You might also like