Sei sulla pagina 1di 7

INSPIRING CREATIVE AND INNOVATIVE MINDS

INTRODUCTION

Structure of C Program Every C program consists of one or more modules called functions. One of the functions must be called main. The program will always begin by executing the main function, which may access other functions. Any other function definitions must be defined separately, either ahead of or after main

INSPIRING CREATIVE AND INNOVATIVE MINDS

INTRODUCTION

Structure of a C Function A function heading, which consists of the function name, followed by an optional list of arguments (variables /parametres), enclosed in parentheses. A list of argument declarations, if arguments are not included in the heading. A compound of statements

INSPIRING CREATIVE AND INNOVATIVE MINDS

BASIC C PROGRAM

main function is mandoary

INSPIRING CREATIVE AND INNOVATIVE MINDS

BASIC C PROGRAM

function heading /name

variable declaration compound statements

INSPIRING CREATIVE AND INNOVATIVE MINDS

BASIC C PROGRAM

acess library file

comments (will not be executed)


(screen) output statement

INSPIRING CREATIVE AND INNOVATIVE MINDS

BASIC C PROGRAM

(user) input statement

INSPIRING CREATIVE AND INNOVATIVE MINDS

BASIC C PROGRAM

assignment statement

INSPIRING CREATIVE AND INNOVATIVE MINDS

PROGRAM EXECUTION In general program execution takes two steps Compile the source code.
Compilation is the process of converting the source code into machine language the very minimalist language that is spoken directly by the machine in use. The machine language is stored in a new file.

Run or execute the machine-language file.

PROGRAM EXECUTION
The preprocessor takes your source code and following certain directives that you give it tweaks it in various ways before compilation. A directive is given as a line of source code starting with the # symbol The preprocessor works in a very crude, word-processor way, simply cutting and pasting it doesnt really know anything about C!
Your source code Enhanced and obfuscated source code Object code

Preprocessor

Compiler
10

SEPARATE COMPILATION Advantage: Quicker compilation When modifying a program, a programmer typically edits only a few source code files at a time. With separate compilation, only the files that have been edited since the last compilation need to be recompiled when re-building the program. For very large programs, this can save a lot of time.
11

PROGRAM COMPILATION
A C program consists of source code in one or more files Each source file is run through the preprocessor and compiler, resulting in a file containing object code Object files are tied together by the linker to form a single executable program
Source code file1.c Source code file2.c Libraries .h or .lib Preprocessor/ Compiler Preprocessor/ Compiler Object code file1.o Object code file2.o

Linker Executable code a .exe

INSPIRING CREATIVE AND INNOVATIVE MINDS

Potrebbero piacerti anche