You are on page 1of 22

CSE1CES:

C Programming For Engineers

Lecturer: Zhen He

Lecture 1

1
My Details

Name: Zhen He

Office: BG 235

Phone Number: 9479 3036

Email: z.he@latrobe.edu.au

Consulation hours: Wed 10am -12pm

2
Lecture Times

Mon 1pm – 2pm Martin Building LT (Rm 141)


Thu 11am – 12pm Martin Building LT (Rm 141)

3

Lab Details
It is very important to come to labs.

Labs start from week 2.

Labs are marked:

1 mark for attempting lab

2 marks for finishing lab

Lab times (labs start from week 2):
Mon 11am – 1pm BG116
Mon 3pm – 5pm BG116
Thu 1pm – 3pm BG116
Thu 3pm – 5pm BG116

Please fill in lab sign up sheet and return to me by Thursday.

Lab assignment will be posted on webct by end of this weekend.

4
Tutors
Name: Phil Ward
Email: pgward@students.latrobe.edu.au
Name: Mitzi McCarthy
Email: ml2mccarthy@students.latrobe.edu.au
Name: Thi Nguyen
Email: nt2nguyen@students.latrobe.edu.au

5
Assessment

One end of semester examination 70 %


One C programming assignment 20 %


Labs 10 %


Must obtain above 50% in both end of semester exam and
above 50 % in rest of assessment to pass course.


C programming assignment due date: Tues 18th of May

6
Books


Text Book

Applications Programming in ANSI C, 3rd edition,
Richard Johnsonbaugh & Martin Kalin, Prentice Hall,
1996.

7
Aims of Course


To a gain a fundamental understanding of the C programming
language.


To be able to write structured C code that functions to user
defined specifications.

8
Learning Outcomes

understand the principals of good C programming style

write robust C code to solve engineering problems

write C code that is efficient in terms of speed of
execution and memory usage

understand the syntax and principals behind memory
management in C

9
Objective of Today's
Lecture


Why learn C?


To understand the basic syntax of the C programming language.

10
Why learn C?

Efficiency

Code generated by the C compiler are typically small in size and
can be executed fast.

Many operating systems are written in C, eg. UNIX, Microsoft
NT, linux, etc.

Portability

Programs can be easily ported onto different software and
hardware platforms.

E.g. Microsoft windows, UNIX, workstations, mainframes, etc.

Modularity

Programs can be broken up into smaller components (called
functions).

Easy to distribute work

Functions can be reused.
11
Example Program
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}

12
The main function
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}


The main function starts the execution of the program.

{ delimits the beginning of the program body

} delimits the end of the program body
13
Comments
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */
char alpha = 'c';
int x1 = 10;
float radius, area, speed;
}


Start of comment is delimited by /*

End of comment is delimited by */

May occur anywhere.

May span many lines.

May not be nested. E.g./* This */ comment is not correct */

Never used by compiler. 14
Keywords
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}


A keyword is a word that has a special meaning to the
programming language.

15
Complete list of C
keywords
auto enum short break exit
sizeof case extern static char
float struct continue goto switch
default if typedef do int
union double register unsigned
else return void entry

16
Identifers
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}


Identifier is a name given to objects such as variables, functions,
etc.

Identifiers must not be keywords.

Allowable characters: alphabetics, digits, underscore

An identifier must start with a nondigit. 17
Data Types
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area speed;
}


The data type determines how an object is interpreted.

18
Data Types (cont.)
Type Bits stored Range/Capacity
(32 bit machine)
Characters
char 8 256 characters

Integers
short int 16 -32768 to 32767
long int 32 -214748648 to 2147483647
int 32 short or long int
short unsigned 16 0 to 65536
long unsigned 32 0 to 429497296
unsigned 32 short or long unsigned

Floating Point
float 32 + 3.4 x 10+ 38 (7 significant figures)
double 64 + 1.7 x 10+ 308 (15 significant figures)
long double 80 + 1.2 x 10+ 4932 (19 significant figures)19
Declarations
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}


A declaration announces variables in the following format:
<type> <comma separated identifier list>;

It causes storage to be allocated

All variable identifiers must be declared before it is used.
20
Identifier Intialization
int main()
{
/* 1. This is a comment.
2. Comments can occur anywhere */

char alpha = 'c';


int x1 = 10;
float radius, area, speed;
}


Variables can be initialized at their declaration or subsequently.

Unless initialized the value stored in a variable is undefined.

21
Conclusion

Why learn C?

Efficiency, portability and modularity.


In this lecture we have gained a basic understanding of the syntax
of the C programming language.


In the next lecture we will learn about constants, expressions and
operators.

22

You might also like