Lec 02
Lec 02
Lec 02
Please make sure you can access Piazza (and can get email notifications of the
messages posted on Piazza in real-time or digest mode)
Prutor availability
During lab hours (1400-1500, M/Tu/Wed/Thu), only in NCL labs
Outside lab hours, hostels, CC, NCL etc (NCL open till 2AM)
Correct Prutor link: https://esc101.cse.iitk.ac.in/ (NOT https://prutor.cse.iitk.ac.in/)
2
Announcements
When logging in on the lab machines (Linux/Windows), use your CC id
(without @iitk.ac.in) and your CC password
We will soon hold some special sessions for students who do not feel very
comfortable with English (will discuss what is being covered in lectures)
Will circulate a form to ask if you need it
We will soon hold a special lab session for students who are not familiar
with operating computers
Will circulate a form to ask if you need it
4
Programming: Some Benefits
Applications in Engineering (civil, chemical), Sciences, Economics, AI
https://www.youtube.com/watch?v=nKIu9yen5nc
People who can code often deal with day-to-day problems more efficiently
5
How to Communicate with Computers?
We need a language to communicate with the computer hardware
Also need to re-write machine code if we want to run the code on another
computer that has a different type of hardware – cumbersome 7
Hello World (in assembly language)
8
Computers and Programming
A better alternative would be to write our programs in a language that is
How: Write the code in a high-level language and translate it into machine
language using another software called “compiler”
9
Computers and Programming
A better alternative would be to write our programs in a language that is
High-level
(example: C) Low-level
(example: Assembly)
Low-level: Form is closer to what the machine’s hardware understands
Examples: Machine Language, Assembly Language
Compiled languages
C C++
Interpreted languages
python JavaScript
Runtime languages
Java 12
Programming Cycle for Compiled Languages
(The typical cycle)
YES
Write/Edit Compilation
Compile Succeeded ? Run
Code
NO
NO Got
Expected YES
Output? (more inputs?)
YES
Done
Note: Some high-level languages are not compiled but use an “interpreter”
to communicate with the hardware (Example: Python, MATLAB, etc) 13
The C Programming Language
A high-level programming language
Widely used. Many operating systems, and even parts of many other
programming languages such as Python were developed using C
#include<stdio.h>
int main(){
printf(“Welcome to ESC101”);
return 0;
}
The program prints “Welcome to ESC101” (without the quotes)
15
Structure of A Simple C Program
Every C program’s entry point
(program’s execution starts Tells C compiler to include the standard
here) is the main function input/output library stdio.h (collection of
with return type integer functions such as printf, scanf, etc)
int main () {
Explore, practice. It
# include <stdio.h> int main () {
int a; # include <stdio.h>
Declare all then int main () {
int a = 1;
int b = 2;will take only a few int b;
int c; assign values int a = 1;
int c; a = 1; int b = 2; Shortcut
c = a + b;days to internalize.
printf(“Result is %d”, c);
b = 2; int c = a + b;
printf(“Result is %d”, c);
c = a + b;
return 0; return 0;
} return 0; How will I
printf(“Result is %d”, c);
}
}
remember
# include <stdio.h>
all this?
int main () { Shortcut # include <stdio.h>
int a,b,c; int main () { Shortcut
a = 1; int a=1,b=2,c;
b = 2; c = a + b;
c = a + b; printf(“Result is %d”, c);
printf(“Result is %d”, c); return 0;
return 0; }
}