Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lesson 1: Introduction To C Programming

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 9

LESSON 1

Introduction to C Programming

Background
High-level
1972

- Dennis Ritchie at AT&T Lab


Intended for system programming
UNIX
C B (1970, Ken Thompson) BCPL (1967, Martin
Richards)

C++
Standard ANSI C
Institute)

(American National Standard

Why C ??

Portable
PCs to mainframes
Speed
Intended used for developing OS
Efficient, compact & direct manipulations
Directly manipulate bits, bytes, words, pointers
High-level features
Structure methodology
Flexible
Many types of programming purposes
Run-time error checking
Array-boundary check, argument-type compatibility

Structure of C Program

(1)

header file declaration


constant value declaration
function declaration
global variable declaration list and initialization

main ()
{
local variable declaration list and initialization
statement 1;
.
.
.
statement n;
return 0;
}
user defined function(s)

Structure of C program

(2)

Where user defined function structure:


function header
{
local data declaration list and initialization
statement 1;
.
.
.
statement n;
[return value;] /*optional*/
}

Preprocessor Directives
Always

begin with the pound sign #


Commands to C preprocessor
Two most common directives:

File Inclusion

Copy of the specified file to be inserted


#include <file.h> or #include file.h

Macro definition & substitution

Define macro subsequent occurrences of


the macro name are replaced by text
#define MAX_SIZE 100
#define sqr(x) ((x)*(x))

Simple C Program 1

Simple C Program 2

You might also like