You are on page 1of 40

CP (CS F111)

BITS Pilani
Hyderabad Campus

Mr. Sanjeev Kr Singh


Lecturer
Department of CSIS

Todays Agenda

Course Logistics
Course Motivation
Course Outline
Basics

CS F111

BITS Pilani, Hyderabad Campus

Course Logistics

Total
Marks =
300

Make-Up Policy :
Makeup for other components is granted on
prior permissions and valid document of illness.
CS F111

BITS Pilani, Hyderabad Campus

Course Logistics
Lab (Practicals)
Once in a week of 2 hours.
Focus on practical aspects of programming and complex problem solving
Online Judge : Mooshak

Lab Evaluation Components

Continuous Lab Evaluation 10%


Lab Eval-1 10 %
Lab Eval-2 15%

Chamber consultation hours

B223 Wednesday (3.00 4.00 pm)

Course Notices:

CMS & CSIS Notice board(B-Block)


CS F111

BITS Pilani, Hyderabad Campus

Our Team
Mr. Sanjeev Singh : Instructor in Charge
Dr. Aruna Malapati : Instructor
Mr. Gokul Kannan : Instructor
Research Scholars : Mr. Pavan, Mr. Sanket , Ms. Rajita
Teaching Assistants : TBA

3 Lectures + 1 Lab every week

CS F111

BITS Pilani, Hyderabad Campus

Text Books

CS F111

BITS Pilani, Hyderabad Campus

Course Motivation
Programming is the core of everything to do with
computers.

Application areas :

Book tickets online


Buy online
Search Something on internet
Weather forecast
Video games
Intelligent Systems : Washing Machines, Fighter planes
Device Drivers

CS F111

BITS Pilani, Hyderabad Campus

Ticket Reservation

CS F111

BITS Pilani, Hyderabad Campus

Buying Online

CS F111

BITS Pilani, Hyderabad Campus

Washing Machine

CS F111

BITS Pilani, Hyderabad Campus

Mars Mission

CS F111

BITS Pilani, Hyderabad Campus

Why Learn C?

C is the basis for many other languages (C++, Java, Perl).

C is very quick.

C is small (only 32 keywords).

C is common (lots of C code).

C is stable (the language doesnt change much).

C is easy to Learn

CS F111

BITS Pilani, Hyderabad Campus

Outcome of this Course


At the end of the course
you should be able to solve a task by developing an
algorithm.
writing and execute its equivalent C program.
Also, you will be able to know little about the components
responsible for executing your program.

CS F111

BITS Pilani, Hyderabad Campus

Course Outline - Overview

Fundamentals

Problem Solving Methodology

Decision making
Looping

Complex Data Types

Data-Types, variables
Standard Input / Output

Programming Constructs

Flowchart and Algorithms

Overview of C programming

Computer Hardware & Software


Programming Language

Arrays
Pointers
Strings
Structures

Modular Programming
Bit-Level Manipulations
File Handling
Linked List and operation on it.
CS F111

BITS Pilani, Hyderabad Campus

What is a Computer ?

CS F111

BITS Pilani, Hyderabad Campus

What is Computer System ?


A computer system includes hardware and software

Things that we
cannot touch

CS F111

BITS Pilani, Hyderabad Campus

Basic Definitions
Bit(Binary Digit) : 0s and 1s
Low Voltage : 0 (off)
High Voltage : 1 (on)

Instruction : Sequence of bits to carry out specific


task

ADD
SUB
MUL
DIV
MOV etc

CS F111

BITS Pilani, Hyderabad Campus

Basic Definitions
Program
task

Set of instructions for carrying out a specific

Where are programs stored?


In secondary memory, when first created.
Brought into main memory, during execution.

Software Collection of programs.


System software

Application software

CS F111

BITS Pilani, Hyderabad Campus

Computer Software
System Software
Programs that manage the hardware resources
Operating System, Compilers, Linkers, Loaders, Debuggers, Disk
formatters, etc.

Application Software
Helps users solve their problems
VLC player, Office, web browsers, DBMS, Banking application,
Reservation systems etc.

CS F111

BITS Pilani, Hyderabad Campus

Anatomy of a Computer
System
User

Application
Software
System
Software
Hardware

CS F111

BITS Pilani, Hyderabad Campus

Computer Hardware
Input Device
Output Device
Memory
Primary Memory
Secondary Memory

Processing Elements

CS F111

BITS Pilani, Hyderabad Campus

Input Device
Input: Getting Data into the Computer

CS F111

BITS Pilani, Hyderabad Campus

Output Device
Output: Displaying Information

CS F111

BITS Pilani, Hyderabad Campus

Primary Memory
Random Access Memory RAM

Cache Memory L1 , L2 cache

CS F111

BITS Pilani, Hyderabad Campus

Secondary Storage Memory


Hard Disk Drive

Flash Drive

Compact Disc
SD Memory Card

CS F111

BITS Pilani, Hyderabad Campus

Memory & Speed Hierarchy

Memory is physically arranged so that fastest elements


(registers) are closest to the CPU and slower elements are
progressively farther away.
Very Nicely explained about how data is
stored on disc :
https://www.youtube.com/watch?v=f3BNHhfTsvk
CS F111

BITS Pilani, Hyderabad Campus

Megabytes, Gigabytes,
Terabytes... What Are They ?
1 Bit = Binary Digit
8 Bits = 1 Byte
word 4 bytes = 32 bits (word size is processor specific)

Base 2 Numbers composed of bits


Base 10 Numbers composed of the digits 0-9
Base 16 Numbers composed of the digits 0-9 and letters A-F. Also called hexadecimal or
hex.

1024 Bytes = 1 Kilobyte


1024 Kilobytes = 1 Megabyte
1024 Megabytes = 1 Gigabyte
1024 Gigabytes = 1 Terabyte

CS F111

BITS Pilani, Hyderabad Campus

Processing Element
Processing : Working on the input data to
produce output
Central Processing
Unit

CS F111

BITS Pilani, Hyderabad Campus

CPU (Central Processing Unit)


- Fetch Decode Execute
- It retrieves instructions from the memory, interprets
(decodes) them, and performs the requested
operation
- It has a large number of registers which temporarily
store data and programs (instructions).

CS F111

BITS Pilani, Hyderabad Campus

Programming Languages
1. Machine Language
2. Assembly Language
3. High-Level Language

CS F111

BITS Pilani, Hyderabad Campus

Machine Language
Expressed in binary.
Directly understood by the computer.
Not portable; varies from one machine type to
another.
Program written for one type of machine will not run on
another type of machine.

Difficult to use in writing programs.

CS F111

BITS Pilani, Hyderabad Campus

Assembly Language
Mnemonic form of machine language.
Easier to use as compared to machine language.
- For example, use ADD instead of 10110100.

Not portable (like machine language).


Requires a translator program called assembler.
Assembly
language
program

Assembler

CS F111

Machine
language
program

BITS Pilani, Hyderabad Campus

Contd.
Assembly language is also difficult to use in writing programs.
Requires many instructions to solve a problem.

Example: Find the average of three numbers.


MOV
ADD

A,X
A,Y

; A=X
; A=A+Y

ADD
DIV
MOV

A,Z
A,3
RES,A

; A=A+Z
; A=A/3
; RES = A

In C,
RES = (X + Y + Z) / 3

CS F111

BITS Pilani, Hyderabad Campus

High-Level Language

Machine language and assembly language are called low-level


languages.
They are closer to the machine.
Difficult to use.

High-level languages are easier to use.


They are closer to the programmer.
Examples:
C, C++, Java

Requires a translator.
Using a software called compiler.

CS F111

BITS Pilani, Hyderabad Campus

Some programmer jargon


Some words that will be used a lot:
Source code: The stuff you type into the computer. The
program you are writing.
Compile (build): Taking source code and making a program
that the computer can understand.
Executable: The compiled program that the computer can run.
Library: Added functions for C programming which are bolted
on to do certain tasks.
Header file: Files ending in .h which are included at the start of
source code.

CS F111

BITS Pilani, Hyderabad Campus

Creating and Running C


Programs
Text
Text editor
editor

#include <stdio.h>
#include <stdio.h>
int main (void)
int main (void)
{
{

}
}

Compiler
Compiler

Linker
Linker
Library
Loader

Source
00110 110
11001
110

Object

00110 110
110

11001

11001 000
-- - - - - 110

01010

-- - - - -- - - -- - - -

Executabl
e

Results
CS F111

BITS Pilani, Hyderabad Campus

Our First C Program: Hello World

Preprocessor
#include <stdio.h>

Comments are good

/* This program prints Hello World */


main( ) means start here
int main()
{
printf(Hello World!\\nn);
return 0;
}
Library command
Brackets define code blocks
CS F111

BITS Pilani, Hyderabad Campus

C doesnt care much about spaces


#include <stdio.h> /* This program prints Hello World */
int main( ) { printf(Hello World!\n); return 0;}

CS F111

BITS Pilani, Hyderabad Campus

Summary
Course related information
Basics
Component of Computer
3 types of Languages
Compilation & First C Program

CS F111

BITS Pilani, Hyderabad Campus

THANK YOU

CS F111

BITS Pilani, Hyderabad Campus