lecture 2 introduction to programming ws2013

23
Introduction to Programming Lecture 2: Introduction to C Mahmoud El-Gayyar [email protected]

Upload: samir-ahmed

Post on 04-Jun-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 1/23

Introduction to Programming

Lecture 2: Introduction to C

Mahmoud El-Gayyar 

[email protected]

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 2/23

Mahmoud El-Gayyar / Advanced Programming 2

Introduction to the course

General information

Syllabus

Course organization

General rules

Introduction to Programming

Programming Skills

Programming Model

Elements of a real Programming Languages

History of C

Compiler Terminology

Review Lecture 1

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 3/23

Mahmoud El-Gayyar / Advanced Programming 3

Introduction to the course

General information

Syllabus

Course organization

General rules

Introduction to Programming

Programming Skills

Programming Model

Elements of a real Programming Languages

History of C

Compiler Terminology

Review Lecture 1

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 4/23

Mahmoud El-Gayyar / Advanced Programming 4

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 5/23

Mahmoud El-Gayyar / Advanced Programming 5

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 6/23

Mahmoud El-Gayyar / Advanced Programming 6

Programming Language 

 A programming language is a tool

Can not perform every task unaided

C language has built-in functions

But not for every thing

C is a dangerous language

Provide low level access to memory

You should be careful while dealing with it

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 7/23Mahmoud El-Gayyar / Advanced Programming 7

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 8/23Mahmoud El-Gayyar / Advanced Programming 8

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 9/23Mahmoud El-Gayyar / Advanced Programming 9

Your First C Program

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

 printf("Hello, world!\n"); return 0; 

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 10/23Mahmoud El-Gayyar / Advanced Programming 10

Your First C Program

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

 printf("Hello, world!\n"); return 0; 

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 11/23Mahmoud El-Gayyar / Advanced Programming 11

Your First C Program

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

 printf("Hello, world!\n"); return 0; 

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 12/23Mahmoud El-Gayyar / Advanced Programming 12

Your First C Program

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

  printf("Hello, world!\n");

return 0; } 

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 13/23Mahmoud El-Gayyar / Advanced Programming 13

Your First C Program

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

 printf("Hello, world!\n"); return 0;

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 14/23Mahmoud El-Gayyar / Advanced Programming 14

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 15/23Mahmoud El-Gayyar / Advanced Programming 15

Your Second C Program

#include <stdio.h>  /* print a few numbers, to illustrate a

simple loop */  int main() { 

int i;  // single line comment for(i = 0; i < 10; i = i + 1)

printf("i is %d\n", i);return 0;

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 16/23Mahmoud El-Gayyar / Advanced Programming 16

Your Second C Program

#include <stdio.h> /* print a few numbers, to illustrate a

simple loop */ int main() { 

int i;  // single line comment for(i = 0; i < 10; i = i + 1)

printf("i is %d\n", i);return 0;

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 17/23Mahmoud El-Gayyar / Advanced Programming 17

Your Second C Program

#include <stdio.h> /* print a few numbers, to illustrate a

simple loop */ int main() { 

int i; // single line comment  for(i = 0; i < 10; i = i + 1)

printf("i is %d\n", i);return 0;

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 18/23Mahmoud El-Gayyar / Advanced Programming 18

Your Second C Program

#include <stdio.h> /* print a few numbers, to illustrate a

simple loop */ int main() { 

int i; // single line comment for(i = 0; i < 10; i = i + 1)

printf("i is %d \n", i);return 0;

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 19/23Mahmoud El-Gayyar / Advanced Programming 19

Introduction to C Langauge

Your First C Program

Let’s have another example 

Program Structure

Outline

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 20/23Mahmoud El-Gayyar / Advanced Programming 20

Program Structure

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 21/23Mahmoud El-Gayyar / Advanced Programming 21

C is Case-Sensitive 

So if you write “ Main”   instead of “ main”   or “ iNt ”  

instead of “ int ”, the compiler will give you an error  

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 22/23Mahmoud El-Gayyar / Advanced Programming 22

1st Good Programming Style (Indentation) 

C don’t  care about spaces 

for(i = 0; i < 10; i = i + 1) printf("%d\n", i); 

for(i = 0; i < 10; i = i + 1) printf("%d\n", i);

for ( i

= 0 ;

i < 10; i =

i + 1

) printf (

"%d\n" , i

) ;

for(i = 0; i < 10; i = i + 1)

printf("%d\n", i);

8/13/2019 Lecture 2 Introduction to Programming Ws2013

http://slidepdf.com/reader/full/lecture-2-introduction-to-programming-ws2013 23/23

C program

May contain several functions

It can also use built-in functions (don’t forget the include) 

Must have a main function It may return a value (0, -1)

Comments can be used to enrich your program and make it more

readable

C is case sensitive

Indentations (white spaces) is a good programming style

Summary