Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to C Language

Similar presentations


Presentation on theme: "Introduction to C Language"— Presentation transcript:

1 Introduction to C Language
Chapter Four 

2 Outline The C character set. Simple Program.
Description of the Program. General Structure of any C program.

3 The C character set The following program shows the major components of a C program as indicated above. The lines are numbered to reference them, they are not part of the C code. You don’t need to worry now about the logic of this program.

4 Simple Program 1. #include <stdio.h> 2. void main( ) 3. { 4. printf( "Welcome " ); 5. printf( "to C!\n" ); 6. /* end function main */ 7. }

5 Line1: It includes a header file called standard
1. #include <stdio.h> 2. void main( ) 3. { printf( "Welcome " ); printf( "to C!\n" ); /* end function main */ 7. } Line1: It includes a header file called standard input and output header file. This file is important in order to introduce data to the program via standard input (such as the keyboard) and to display data on a standard output (such as the screen).

6 1. #include <stdio.h>
2. void main( ) 3. { printf( "Welcome " ); printf( "to C!\n" ); /* end function main */ 7. } Line 2 : Dcelares a function called name of type void. Inside the parentheses ( ) we can include arguments (will be discussed later).

7 1. #include <stdio.h>
2. void main( ) 3. { printf( "Welcome " ); printf( "to C!\n" ); /* end function main */ 7. } Lines 3 and 7 : Include the left brace { and the right brace }. We refer to the statements within these braces as compound statements since they are surrounded by these braces.

8 Lines 4 , 5 : are called statements.
1. #include <stdio.h> 2. void main( ) 3. { printf( "Welcome " ); printf( "to C!\n" ); /* end function main */ 7. } Lines 4 , 5 : are called statements.

9 1. #include <stdio.h>
2. void main( ) 3. { printf( "Welcome " ); printf( "to C!\n" ); /* end function main */ 7. } Line 6 : Includes /* end function main*/. This is a comment and is ignored by the compiler.

10 General Structure of any C program
The general skeleton (structure) of any C program is: #include <stdio.h> void main( ) { ……… }

11 Notice that, because of the different standards, the skeleton of the program can be written as follow: #include <stdio.h> int main( ) /* instead of void main( ) */ { ……… return 0; /* as a result of using int main( ) */ } The right brace } and the left brace { are referred to as Compound Statements.


Download ppt "Introduction to C Language"

Similar presentations


Ads by Google