Escolar Documentos
Profissional Documentos
Cultura Documentos
http://www.iitk.ac.in/doaaold/timetable/coreschedule2015-16-2.pdf
Esc101, Programming
A Simple Program
# include <stdio.h>
int main(){
printf(Welcome to ESC101);
return 0;
}
The program prints the message Welcome to ESC101
8/3/2015
Esc101, Programming
# include <stdio.h>
int main(){
int a = 17;
int b = 23;
int c;
c = a + b;
printf(Result is %d, c);
return 0;
}
The program prints the message: Result is 40
8/3/2015
Esc101, Programming
# include <stdio.h>
int main ()
{
int a = 17;
int b = 23;
int c;
c = a + b;
printf(Result is %d,c);
return 0;
}
+ is an operator used
to add two numbers.
The numbers come
from the values
stored in the boxes
named a and b
8/3/2015
= 17 stores value 17
in the box that we have
named a.
It is OK to skip this
part and store value
later as we do for box
named c.
Types
1/11/2015
Esc101, Programming
Types
Type:
1/11/2015
A set of values
A set of operations on these values
Esc101, Programming
Types
Type:
A set of values
A set of operations on these values
Natural numbers
1, 2, 3, values
+, - , *, >, <, operations
Complex numbers
5 + 3i, 7 + 2i,
+, - , *, /, conjugate,
NO >, < operations
1/11/2015
Esc101, Programming
Data Types in C
1/11/2015
Esc101, Programming
Data Types in C
int
1/11/2015
Esc101, Programming
Data Types in C
int
float
1/11/2015
Esc101, Programming
Data Types in C
int
float
double
1/11/2015
Esc101, Programming
Data Types in C
int
float
double
char
1/11/2015
Esc101, Programming
1/11/2015
Esc101, Programming
a, A, 6, $
1/11/2015
Esc101, Programming
a, A, 6, $
Case sensitive
a is not same as A
1/11/2015
Esc101, Programming
a, A, 6, $
Case sensitive
a is not same as A
1/11/2015
Esc101, Programming
a, A, 6, $
Case sensitive
a is not same as A
Special characters:
1/11/2015
Esc101, Programming
1/11/2015
Esc101, Programming
1/11/2015
Esc101, Programming
1/11/2015
Esc101, Programming
Esc101, Programming
#include <limits.h>
#include <stdio.h>
int main() {
printf("Min=%d, Max=%d",
INT_MIN, INT_MAX);
return 0;
}
1/11/2015
Esc101, Programming
#include <limits.h>
#include <stdio.h>
int main() {
printf("Min=%d, Max=%d",
INT_MIN, INT_MAX);
return 0;
}
OUTPUT:
1/11/2015
Esc101, Programming
#include <limits.h>
#include <stdio.h>
int main() {
printf("Min=%d, Max=%d",
INT_MIN, INT_MAX);
return 0;
}
OUTPUT: Min=-2147483648, Max=2147483647
1/11/2015
Esc101, Programming
#include <limits.h>
#include <stdio.h>
int main() {
printf("Min=%d, Max=%d",
INT_MIN, INT_MAX);
return 0;
}
OUTPUT: Min=-2147483648, Max=2147483647
Esc101, Programming
#include <limits.h>
#include <stdio.h>
int main() {
printf("Min=%d, Max=%d",
INT_MIN, INT_MAX);
return 0;
}
OUTPUT: Min=-2147483648, Max=2147483647
Esc101, Programming
#include <stdio.h>
int main() {
float y = 100000009.0;
printf("Value of y is %f", y);
return 0;
}
1/11/2015
Esc101, Programming
10
#include <stdio.h>
int main() {
float y = 100000009.0;
printf("Value of y is %f", y);
%f is the
placeholder
for float.
return 0;
}
1/11/2015
Esc101, Programming
10
#include <stdio.h>
int main() {
float y = 100000009.0;
printf("Value of y is %f", y);
%f is the
placeholder
for float.
return 0;
}
OUTPUT:
1/11/2015
Esc101, Programming
10
#include <stdio.h>
int main() {
float y = 100000009.0;
printf("Value of y is %f", y);
%f is the
placeholder
for float.
return 0;
}
OUTPUT: Value of y is 100000008.0
1/11/2015
Esc101, Programming
10
Function main
1/11/2015
Esc101, Programming
11
Function main
The point at which C program begins its execution
1/11/2015
Esc101, Programming
11
Function main
The point at which C program begins its execution
Every complete C program must have exactly one
main
int main () { }
1/11/2015
Esc101, Programming
11
Function main
The point at which C program begins its execution
Every complete C program must have exactly one
main
int main () { }
1/11/2015
Esc101, Programming
11
Function main
Arguments: none ()
1/11/2015
Esc101, Programming
12
Line
No.
Line
No.
Output:
Line
No.
Line
No.
Line
No.
Variables
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
3.1416
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
3.1416
Variables can change their value during
program
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
3.1416
Variables can change their value during
program
f = 2.7183;
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
3.1416
Variables can change their value during
program
f = 2.7183;
3.1416
1/11/2015
Esc101, Programming
14
Variables
A name associated with memory cells (boxes) that store data
Type of variable determines the size of the
box.
int m = 64;
64
char c = X;
X
float f = 3.1416;
3.1416
Variables can change their value during
program
f = 2.7183;
2.7183
1/11/2015
Esc101, Programming
14
1/11/2015
Esc101, Programming
15
1/11/2015
Esc101, Programming
15
1/11/2015
Esc101, Programming
15
Variable Declaration
1/11/2015
Esc101, Programming
16
Variable Declaration
To communicate to compiler the names and
types of the variables used by the program
1/11/2015
Esc101, Programming
16
Variable Declaration
To communicate to compiler the names and
types of the variables used by the program
int count;
1/11/2015
Esc101, Programming
16
Variable Declaration
To communicate to compiler the names and
types of the variables used by the program
int count;
int min = 5;
1/11/2015
Esc101, Programming
16
Identifiers
1/11/2015
Esc101, Programming
17
Identifiers
Names given to different objects
1/11/2015
Esc101, Programming
17
Identifiers
Names given to different objects
1/11/2015
Esc101, Programming
17
Identifiers
Names given to different objects
1/11/2015
Esc101, Programming
17
Identifiers
Names given to different objects
1/11/2015
Esc101, Programming
17
Identifiers
1/11/2015
Esc101, Programming
18
Choosing Identifiers
1/11/2015
Esc101, Programming
19
Choosing Identifiers
1/11/2015
Esc101, Programming
19
Choosing Identifiers
Choose meaningful names
1/11/2015
count vs c vs tmp1
Esc101, Programming
19
Choosing Identifiers
Choose meaningful names
count vs c vs tmp1
1/11/2015
count vs c_o_u_n_t
Esc101, Programming
19
Choosing Identifiers
Choose meaningful names
count vs c vs tmp1
count vs c_o_u_n_t
1/11/2015
Max vs Maximum
Esc101, Programming
19
Choosing Identifiers
Choose meaningful names
count vs c vs tmp1
count vs c_o_u_n_t
Max vs Maximum
1/11/2015
a_loop_counter vs counter vs i
Esc101, Programming
19