Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Mythili Vutukuru

IIT Bombay

Reference: “C How to Program”, Deitel and Deitel, 8th Edition, Chapters 1&2
 Computer hardware is the physical machinery of a computer
 CPU runs instructions on data (e.g., add two numbers), ~109 instructions per second
 Main memory or Random Access Memory (RAM) stores instructions and user data in “volatile”
memory (erased when power is off)
 Hard disk stores user files persistently (retained even when power is off)
 Input/Output devices: keyboard, mouse, monitor, network card, …

 Computer software makes hardware do useful things


 Program: Sequence of instructions written by a user to execute a specific task on user data
 Example: A program to take input of two numbers, add them, print output
 Example: A program to fetch a web page from Internet, or play a video

 Software instructions/data reside in main memory and run on CPU


 Bit: 0 or 1, basic unit of information
 Byte: Collection of 8 bytes, unit of storage
of information in computers
 Data types: different types of data stored
by users
 Character (1 byte): decimal digits (0–9),
letters (A–Z and a–z), and special symbols
(e.g., $, @, %, &, *, +, ….)
 String of characters
 Integer (4 bytes)
 Floating point numbers

 Data organized as fields, records, files


 Modern computers have few GB RAM and few TB hard disk storage
 Computer program = user data + instructions to operate on the data
 Example: marks of student, and instructions to add marks to calculate total

 Programming language = language in which programs are written by a user


 Machine language = language that computer can understand
 Consists of series of bits, hard for humans to write programs in machine language

 High-level language = language that humans can easily write programs in


 Example: use statements like “sum = number1 + number2”
 Example: C, C++, Java

 But how does a computer understand a program written in a high-level language?


 Compiler translates high-level language code to machine code
 User writes a program (welcome.c) using any text editor, saves file on hard disk
 User compiles program (gcc welcome.c) using compiler
 Compiler performs many steps, prints any errors to screen

 Compiler generates executable (machine code) which is saved on disk


 Default name of executable file is “a.out”

 User runs program (machine code) by typing “./a.out” at terminal


 Program instructions and data loaded into main memory
 CPU runs instructions of the program one by one, and generates output
 Real life programs do more complex, useful work
 Applications such as Code Blocks allow you to write, build (compile) and run
program from the same interface
 Works across Windows and Linux

 The program picks a number between 1 and 1000, asks user to guess it
 User types a number via the keyboard as input to the program
 Program checks if number if higher or lower than the number is picked, and
conveys feedback to user
 User can guess again based on this feedback, until he gets it right
 Editor allows users to write program code or any other text
 Compiler translates high level language code to machine format that computer can
understand
 Terminal is a place to give instructions to computer to open editor, compile
program, run program
 IDE (integrated development environment) allows you to write and run code from
the same interface
 Standard output is where users can see output of their program (screen)
 Standard input is where users can give inputs to running program (keyboard)
 Standard C library provides “functions” (shortcuts) that user can call to read input
or print output to screen
Multiple statements in a program, keywords in dark blue

Comments

Include standard library functions to refer to existing functions

Main part of any program


Call library function to print to standard output
Statements end with ;
Opening and closing braces { } to group statements

What you see on screen when you compile and run the program
The usage of \n causes new line
Can insert multiple new lines in one print statement

You might also like