Sie sind auf Seite 1von 13

CHAPTER 3

C FUNDAMENTALS

COURSE LEARNING OUTCOME (CLO) : CLO 3 - Use an appropriate data type for a particular solution. CLO 4 Use a high level programming language in solving variety engineering

and scientific problems.

STRUCTURE OF C PROGRAMME

EC201 - FUNDAMENTAL PROGRAMMING

Structure of C programme
The C program starting point is identified by the word main() This inform the computer as to where the program actually start The 2 braces { and } signify the begin and end segment of the program
3

EC201 - FUNDAMENTAL PROGRAMMING

Structure of C
The purpose of #include< #include<stdio.h> is to allow the use of the printf statement to provide program output For each function built into the language an associated header file must be included Text to be displayed by printf must be enclosed in double quotes
4 EC201 - FUNDAMENTAL PROGRAMMING

Compile C Program
Compilation refers to the processing of source code files (.c, .cc, or . .cpp) and the creation of an 'object' file The compiler merely produces the machine language instructions that correspond to the source code file that was compiled
5

EC201 - FUNDAMENTAL PROGRAMMING

Executable File
These are produced as the output of a program called a "linker". The linker links together a number of object files to produce a binary file which can be directly executed. Binary executables have no special suffix on Unix operating systems, although they generally end in ".exe" on Windows
6

EC201 - FUNDAMENTAL PROGRAMMING

Header File
Contain definition function and variables which can be incorporated into any C program by using the pre pre-processor #include statement To use any of the standard function, the appropriate file should be included All header file have the extension of .h and generally reside in the /usr/include subdirectories

Example : #include<math.h #include<string.h> math.h>,


EC201 - FUNDAMENTAL PROGRAMMING

Header File
The use of angle < > inform the compiler < > to search compiler include directories for the specified files

EC201 - FUNDAMENTAL PROGRAMMING

Symbolic constant
Name given to the value that cannot be change Implemented with the #define preprocessor directive

Example:

#define pi 3.14159 #define FALSE 0


9

The whole point of using #define is to make easier to read and modify
EC201 - FUNDAMENTAL PROGRAMMING

Example

10

EC201 - FUNDAMENTAL PROGRAMMING

Return Statement
The return statement terminates the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call

11

EC201 - FUNDAMENTAL PROGRAMMING

The Usage of comment


Why use comment ?

Documentation of variables and function of their usage Explaining difficult section of code Describe the program, author , date, modification changes, revision,etc

Use /* close */ or // for single line


12

EC201 - FUNDAMENTAL PROGRAMMING

Example of comment usage

13

EC201 - FUNDAMENTAL PROGRAMMING

Das könnte Ihnen auch gefallen