ogramming - wikimedia€¦ · 103 105 109 110 12.4 sizeof 116 117 12.6 const 119 120 124 125 137...

719
C Programming Wikibooks.org

Upload: others

Post on 23-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

  • CPr

    ogra

    mm

    ing

    Wik

    iboo

    ks.o

    rg

  • July

    1,20

    12

    On

    the

    28th

    ofA

    pril

    2012

    the

    cont

    ents

    ofth

    eEn

    glis

    has

    wel

    las

    Ger

    man

    Wik

    iboo

    ksan

    dW

    ikip

    edia

    proj

    ects

    wer

    elic

    ense

    dun

    -de

    rCre

    ativ

    eC

    omm

    ons

    Attr

    ibut

    ion-

    Shar

    eAlik

    e3.

    0U

    npor

    ted

    licen

    se.A

    nU

    RIt

    oth

    islic

    ense

    isgi

    ven

    inth

    elis

    toffi

    gure

    son

    page

    685.

    Ifth

    isdo

    cum

    enti

    sa

    deriv

    edw

    ork

    from

    the

    cont

    ents

    ofon

    eof

    thes

    epr

    ojec

    tsan

    dth

    eco

    nten

    twas

    still

    licen

    sed

    byth

    epr

    ojec

    tun

    der

    this

    licen

    seat

    the

    time

    ofde

    rivat

    ion

    this

    docu

    men

    thas

    tobe

    licen

    sed

    unde

    rth

    esa

    me,

    asi

    mila

    ror

    aco

    mpa

    tible

    licen

    se,a

    sst

    ated

    inse

    ctio

    n4b

    ofth

    elic

    ense

    .The

    listo

    fcon

    tribu

    tors

    isin

    clud

    edin

    chap

    terC

    ontri

    buto

    rson

    page

    647.

    The

    licen

    sesG

    PL,L

    GPL

    and

    GFD

    Lar

    ein

    clud

    edin

    chap

    -te

    rLic

    ense

    son

    page

    691,

    sinc

    eth

    isbo

    okan

    d/or

    parts

    ofit

    may

    orm

    ayno

    tbe

    licen

    sed

    unde

    ron

    eor

    mor

    eof

    thes

    elic

    ense

    s,an

    dth

    usre

    quir

    ein

    clus

    ion

    ofth

    ese

    licen

    ses.

    The

    licen

    ses

    ofth

    efig

    ures

    are

    give

    nin

    the

    listo

    ffigu

    res

    onpa

    ge68

    5.

  • Con

    tent

    s1

    Why

    lear

    nC

    ?.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .3

    2H

    isto

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .11

    3W

    haty

    oune

    edbe

    fore

    you

    can

    lear

    n.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .15

    3.1

    Get

    ting

    Star

    ted

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    153.

    2Fo

    otno

    tes

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .30

    4U

    sing

    aC

    ompi

    ler

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .31

    5A

    tast

    eof

    C.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    436

    Intr

    oex

    erci

    se.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .49

    6.1

    Intr

    oduc

    tory

    Exe

    rcis

    es.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .50

    7B

    egin

    ning

    C.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    558

    Prel

    imin

    arie

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .57

    8.1

    Bas

    icC

    once

    pts

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    57

    III

  • 8.2

    Blo

    ckSt

    ruct

    ure,

    Stat

    emen

    ts,W

    hite

    spac

    e,an

    dSc

    ope

    ..

    ..

    ..

    ..

    588.

    3B

    asic

    sof

    Usi

    ngFu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    618.

    4T

    heSt

    anda

    rdL

    ibra

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .63

    8.5

    Com

    men

    tsan

    dC

    odin

    gSt

    yle

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    649

    Com

    pilin

    g.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .67

    9.1

    Prep

    roce

    ssor

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .69

    9.2

    Synt

    axC

    heck

    ing

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .70

    9.3

    Obj

    ectC

    ode

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    719.

    4L

    inki

    ng.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .72

    9.5

    Aut

    omat

    ion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .72

    10St

    ruct

    ure

    and

    styl

    e.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .75

    10.1

    CSt

    ruct

    ure

    and

    Styl

    e.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .75

    10.2

    Intr

    oduc

    tion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .76

    10.3

    Lin

    eB

    reak

    san

    dIn

    dent

    atio

    n.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    7810

    .4C

    omm

    ents

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    8510

    .5L

    inks

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .94

    11E

    rror

    hand

    ling

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    9511

    .1Pr

    even

    ting

    divi

    deby

    zero

    erro

    rs.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    9811

    .2Si

    gnal

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .10

    011

    .3se

    tjmp

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .101

  • 12V

    aria

    bles

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .10

    312

    .1D

    ecla

    ring

    ,Ini

    tializ

    ing,

    and

    Ass

    igni

    ngV

    aria

    bles

    ..

    ..

    ..

    ..

    ..

    105

    12.2

    Lite

    rals

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    109

    12.3

    The

    Four

    Bas

    icD

    ata

    Type

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    110

    12.4

    sizeof

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .11

    612

    .5D

    ata

    type

    mod

    ifier

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    117

    12.6

    const

    qual

    ifier

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .11

    912

    .7M

    agic

    num

    bers

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    120

    12.8

    Scop

    e.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    124

    12.9

    Oth

    erM

    odifi

    ers

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .12

    513

    Sim

    ple

    Inpu

    tand

    Out

    put

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    137

    13.1

    Out

    putu

    sing

    prin

    tf()

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .13

    813

    .2O

    ther

    outp

    utm

    etho

    ds.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .14

    513

    .3fp

    uts(

    ).

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .14

    613

    .4In

    putu

    sing

    scan

    f()

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    147

    13.5

    Lin

    ks.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .151

    14Si

    mpl

    em

    ath

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .15

    314

    .1O

    pera

    tors

    and

    Ass

    ignm

    ents

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .15

    315

    Furt

    herm

    ath

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..1

    7115

    .1Tr

    igon

    omet

    ric

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .17

    2

  • 15.2

    Hyp

    erbo

    licfu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    175

    15.3

    Exp

    onen

    tiala

    ndlo

    gari

    thm

    icfu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    177

    15.4

    Pow

    erfu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    184

    15.5

    Nea

    rest

    inte

    ger,

    abso

    lute

    valu

    e,an

    dre

    mai

    nder

    func

    tions

    ..

    ..

    ..

    187

    15.6

    Err

    oran

    dga

    mm

    afu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    194

    15.7

    Furt

    herr

    eadi

    ng.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .19

    616

    Con

    trol

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .19

    716

    .1C

    ondi

    tiona

    ls.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    198

    16.2

    Loo

    ps.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .21

    916

    .3O

    nela

    stth

    ing:

    goto

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .23

    016

    .4E

    xam

    ples

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .23

    416

    .5Fu

    rthe

    rrea

    ding

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    235

    17Pr

    oced

    ures

    and

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    237

    17.1

    Mor

    eon

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    240

    17.2

    Wri

    ting

    func

    tions

    inC

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .241

    17.3

    Usi

    ngC

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    248

    17.4

    Func

    tions

    from

    the

    CSt

    anda

    rdL

    ibra

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    249

    17.5

    Var

    iabl

    e-le

    ngth

    argu

    men

    tlis

    ts.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .25

    818

    Prep

    roce

    ssor

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .26

    518

    .1D

    irec

    tives

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    266

  • 18.2

    Use

    fulP

    repr

    oces

    sorM

    acro

    sfo

    rDeb

    uggi

    ng.

    ..

    ..

    ..

    ..

    ..

    ..

    290

    19L

    ibra

    ries

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .30

    719

    .1Fu

    rthe

    rrea

    ding

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    315

    20St

    anda

    rdlib

    rari

    es.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .31

    720

    .1H

    isto

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .31

    820

    .2D

    esig

    n.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .32

    020

    .3A

    NSI

    Stan

    dard

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .321

    20.4

    Com

    mon

    supp

    ortl

    ibra

    ries

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    330

    20.5

    Com

    pile

    rbui

    lt-in

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .33

    220

    .6PO

    SIX

    stan

    dard

    libra

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    333

    21Fi

    leIO

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    335

    21.1

    Intr

    oduc

    tion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .33

    521

    .2St

    ream

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .33

    721

    .3St

    anda

    rdSt

    ream

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .33

    921

    .4FILE

    poin

    ters

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .341

    21.5

    Ope

    ning

    and

    Clo

    sing

    File

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .34

    221

    .6O

    ther

    file

    acce

    ssfu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .34

    621

    .7Fu

    nctio

    nsth

    atM

    odif

    yth

    eFi

    lePo

    sitio

    nIn

    dica

    tor

    ..

    ..

    ..

    ..

    ..

    349

    21.8

    Err

    orH

    andl

    ing

    Func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    354

    21.9

    Oth

    erO

    pera

    tions

    onFi

    les

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    357

  • 21.1

    0R

    eadi

    ngfr

    omFi

    les

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .361

    21.1

    1W

    ritin

    gto

    File

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    384

    21.1

    2R

    efer

    ence

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .40

    822

    Beg

    inni

    ngex

    erci

    ses

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .40

    922

    .1V

    aria

    bles

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .40

    922

    .2Si

    mpl

    eI/

    O.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .41

    622

    .3Pr

    ogra

    mFl

    ow.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .42

    722

    .4Fu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    428

    22.5

    Mat

    h.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    428

    23In

    -dep

    thC

    idea

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    433

    24A

    rray

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .43

    524

    .1A

    rray

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .43

    624

    .2St

    ring

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .44

    225

    Poin

    ters

    and

    arra

    ys.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    445

    25.1

    Dec

    lari

    ngpo

    inte

    rs.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .44

    825

    .2A

    ssig

    ning

    valu

    esto

    poin

    ters

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..4

    5125

    .3Po

    inte

    rder

    efer

    enci

    ng.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .45

    425

    .4Po

    inte

    rsan

    dA

    rray

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    457

    25.5

    Poin

    ters

    inFu

    nctio

    nA

    rgum

    ents

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .46

    425

    .6Po

    inte

    rsan

    dTe

    xtSt

    ring

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .46

    5

  • 25.7

    Poin

    ters

    toFu

    nctio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .46

    825

    .8Pr

    actic

    alus

    eof

    func

    tion

    poin

    teri

    nC

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .471

    25.9

    Exa

    mpl

    esof

    poin

    terc

    onst

    ruct

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    477

    25.1

    0si

    zeof

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .47

    925

    .11

    Ext

    erna

    lLin

    ks.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .48

    626

    Mem

    ory

    man

    agem

    ent

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    489

    26.1

    Mal

    loc

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    490

    26.2

    Thecalloc

    func

    tion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    495

    26.3

    Therealloc

    func

    tion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .49

    626

    .4T

    hefree

    func

    tion

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .49

    726

    .5R

    efer

    ence

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .50

    027

    Stri

    ngs

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .501

    27.1

    Synt

    ax.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .50

    227

    .2T

    he<string.h>

    Stan

    dard

    Hea

    der

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    506

    27.3

    Exa

    mpl

    es.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    543

    27.4

    Furt

    herr

    eadi

    ng.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .54

    528

    Com

    plex

    type

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    547

    28.1

    Dat

    ast

    ruct

    ures

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    547

    28.2

    Type

    mod

    ifier

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .55

    4

  • 29N

    etw

    orki

    ngin

    UN

    IX.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .55

    529

    .1A

    sim

    ple

    clie

    nt.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .55

    529

    .2A

    sim

    ple

    serv

    er.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .561

    29.3

    Use

    fuln

    etw

    ork

    func

    tions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    565

    29.4

    File

    tran

    sfer

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .56

    629

    .5FA

    Qs

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..5

    7130

    Com

    mon

    prac

    tices

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .57

    330

    .1D

    ynam

    icm

    ultid

    imen

    sion

    alar

    rays

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    574

    30.2

    Con

    stru

    ctor

    san

    dde

    stru

    ctor

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    579

    30.3

    Nul

    ling

    free

    dpo

    inte

    rs.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .58

    230

    .4M

    acro

    conv

    entio

    ns.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .58

    530

    .5Fu

    rthe

    rrea

    ding

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    587

    31C

    and

    beyo

    nd.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .58

    932

    Lan

    guag

    eex

    tens

    ions

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .591

    32.1

    Ext

    erna

    llin

    ks.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .59

    333

    Mix

    ing

    lang

    uage

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .59

    533

    .1A

    ssem

    bler

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    595

    33.2

    Cg

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    596

    33.3

    Java

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    597

    33.4

    Perl

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    598

  • 33.5

    Pyth

    on.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .60

    033

    .6Fo

    rfur

    ther

    read

    ing

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    600

    33.7

    Ref

    eren

    ces

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    600

    34C

    ode

    libra

    ry.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .601

    35C

    ompu

    terP

    rogr

    amm

    ing

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    603

    36St

    atem

    ents

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    605

    37C

    Ref

    eren

    ceTa

    bles

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .60

    738

    Ref

    eren

    ceTa

    bles

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    609

    38.1

    Lis

    tofK

    eyw

    ords

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .60

    938

    .2L

    isto

    fSta

    ndar

    dH

    eade

    rs.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    612

    38.3

    Tabl

    eof

    Ope

    rato

    rs.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .61

    538

    .4Ta

    ble

    ofD

    ata

    Type

    s.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    623

    39C

    ompi

    lers

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .641

    39.1

    Free

    (orw

    itha

    free

    vers

    ion)

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..6

    4139

    .2C

    omm

    erci

    al.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    644

    40C

    ontr

    ibut

    ors

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .64

    7L

    isto

    fFig

    ures

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    685

    41L

    icen

    ses

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..6

    9141

    .1G

    NU

    GE

    NE

    RA

    LPU

    BL

    ICL

    ICE

    NSE

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .691

    41.2

    GN

    UFr

    eeD

    ocum

    enta

    tion

    Lic

    ense

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .70

    0

  • 41.3

    GN

    UL

    esse

    rGen

    eral

    Publ

    icL

    icen

    se.

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .70

    7

  • 1W

    hyle

    arn

    C?

    C1

    isth

    em

    ostc

    omm

    only

    used

    prog

    ram

    min

    gla

    ngua

    ge2

    forw

    ritin

    gop

    erat

    ing

    syst

    ems3

    .Uni

    x4w

    asth

    efir

    stop

    erat

    ing

    syst

    emw

    ritte

    nin

    C.L

    ater

    Mic

    roso

    ftW

    indo

    ws5

    ,Mac

    OS

    X6 ,

    and

    GN

    U/L

    inux

    7w

    ere

    allw

    ritte

    nin

    C.N

    oton

    lyis

    1http://en.wikipedia.org/wiki/C%20%28programming%

    20language%29

    2http://en.wikipedia.org/wiki/programming%20language

    3http://en.wikipedia.org/wiki/operating%20systems

    4http://en.wikipedia.org/wiki/Unix

    5http://en.wikipedia.org/wiki/Microsoft%20Windows

    6http://en.wikipedia.org/wiki/Mac%20OS%20X

    7http://en.wikipedia.org/wiki/Linux

    3

    http://en.wikipedia.org/wiki/C%20%28programming%20language%29http://en.wikipedia.org/wiki/C%20%28programming%20language%29http://en.wikipedia.org/wiki/programming%20languagehttp://en.wikipedia.org/wiki/operating%20systemshttp://en.wikipedia.org/wiki/Unixhttp://en.wikipedia.org/wiki/Microsoft%20Windowshttp://en.wikipedia.org/wiki/Mac%20OS%20Xhttp://en.wikipedia.org/wiki/Linux

  • Cth

    ela

    ngua

    geof

    oper

    atin

    gsy

    stem

    s,it

    isth

    epr

    ecur

    sor

    and

    insp

    irat

    ion

    for

    alm

    osta

    llof

    the

    mos

    tpop

    ular

    high

    -lev

    ella

    ngua

    ges

    avai

    labl

    eto

    day.

    Infa

    ct,

    Perl

    8 ,PH

    P9,a

    ndPy

    thon

    10ar

    eal

    lwri

    tten

    inC

    .

    By

    way

    ofan

    alog

    y,le

    t'ssa

    yth

    atyo

    uw

    ere

    goin

    gto

    bele

    arni

    ngSp

    anis

    h,Ita

    lian,

    Fren

    ch,o

    rPor

    tugu

    ese.

    Do

    you

    thin

    kkn

    owin

    gL

    atin

    wou

    ldbe

    help

    ful?

    Just

    asL

    atin

    was

    the

    basi

    sof

    allo

    fth

    ose

    lang

    uage

    s,kn

    owin

    gC

    will

    enab

    leyo

    uto

    unde

    rsta

    ndan

    dap

    prec

    iate

    anen

    tire

    fam

    ilyof

    prog

    ram

    min

    gla

    ngua

    ges

    built

    upon

    the

    trad

    ition

    sof

    C.K

    now

    ledg

    eof

    Cen

    able

    sfr

    eedo

    m.

    1.0.

    1W

    hyC

    ,and

    nota

    ssem

    bly

    lang

    uage

    ?

    Whi

    leas

    sem

    bly

    lang

    uage

    can

    prov

    ide

    spee

    dan

    dm

    axim

    umco

    ntro

    lof

    the

    prog

    ram

    ,Cpr

    ovid

    espo

    rtab

    ility

    .

    8http://en.wikipedia.org/wiki/Perl

    9http://en.wikipedia.org/wiki/PHP

    10http://en.wikipedia.org/wiki/Python%20%28programming%

    20language%29

    http://en.wikipedia.org/wiki/Perlhttp://en.wikipedia.org/wiki/PHPhttp://en.wikipedia.org/wiki/Python%20%28programming%20language%29http://en.wikipedia.org/wiki/Python%20%28programming%20language%29

  • Diff

    eren

    tpr

    oces

    sors

    are

    prog

    ram

    med

    usin

    gdi

    ffer

    ent

    Ass

    embl

    yla

    ngua

    ges

    and

    havi

    ngto

    choo

    sean

    dle

    arn

    only

    one

    ofth

    emis

    too

    arbi

    trar

    y.In

    fact

    ,on

    eof

    the

    mai

    nst

    reng

    ths

    ofC

    isth

    atit

    com

    bine

    sun

    iver

    salit

    yan

    dpo

    rtab

    ility

    acro

    ssva

    riou

    sco

    mpu

    tera

    rchi

    tect

    ures

    whi

    lere

    tain

    ing

    mos

    toft

    heco

    ntro

    lof

    the

    hard

    war

    epr

    ovid

    edby

    asse

    mbl

    yla

    ngua

    ge.

    Fore

    xam

    ple,

    Cpr

    ogra

    ms

    can

    beco

    mpi

    led

    and

    run

    onth

    eH

    P50

    gca

    lcul

    ator

    (AR

    Mpr

    oces

    sor)

    ,the

    TI-

    89ca

    lcul

    ator

    (680

    00pr

    oces

    sor)

    ,Pal

    mO

    SC

    obal

    tsm

    artp

    hone

    s(A

    RM

    proc

    esso

    r),t

    heor

    igin

    aliM

    ac(P

    ower

    PC),

    the

    Ard

    uino

    (Atm

    elAV

    R),

    and

    the

    Inte

    liM

    ac(I

    ntel

    Cor

    e2

    Duo

    ).Ea

    chof

    thes

    ede

    vice

    sha

    sits

    own

    asse

    mbl

    yla

    ngua

    geth

    atis

    com

    plet

    ely

    inco

    mpa

    tible

    with

    the

    asse

    mbl

    yla

    ngua

    geof

    any

    othe

    r.

    Ass

    embl

    y11 ,

    whi

    leex

    trem

    ely

    pow

    erfu

    l,is

    sim

    ply

    too

    diffi

    cult

    topr

    ogra

    mla

    rge

    appl

    icat

    ions

    and

    hard

    tore

    ador

    inte

    rpre

    tin

    alo

    gica

    lway

    .C

    isa

    com

    pile

    dla

    ngua

    ge,w

    hich

    crea

    tes

    fast

    and

    effic

    ient

    exec

    utab

    lefil

    es.

    Itis

    also

    asm

    all

    "wha

    tyo

    use

    eis

    all

    you

    get"

    lang

    uage

    :a

    Cst

    atem

    ent

    corr

    espo

    nds

    toat

    11http://en.wikipedia.org/wiki/Assembly%20language

    http://en.wikipedia.org/wiki/Assembly%20language

  • mos

    taha

    ndfu

    lofa

    ssem

    bly

    stat

    emen

    ts,e

    very

    thin

    gel

    seis

    prov

    ided

    bylib

    rary

    func

    tions

    .

    Sois

    itan

    yw

    onde

    rtha

    tCis

    such

    apo

    pula

    rlan

    guag

    e?

    Lik

    eto

    pplin

    gdo

    min

    oes,

    the

    next

    gene

    ratio

    nof

    prog

    ram

    sfo

    llow

    sth

    etr

    end

    ofits

    ance

    stor

    s.O

    pera

    ting

    syst

    ems

    desi

    gned

    inC

    alw

    ays

    have

    syst

    emlib

    rari

    esde

    sign

    edin

    C.T

    hose

    syst

    emlib

    rari

    esar

    ein

    turn

    used

    tocr

    eate

    high

    er-l

    evel

    libra

    ries

    (like

    Ope

    nGL1

    2 ,or

    GTK

    13),

    and

    the

    desi

    gner

    sof

    thos

    elib

    rarie

    sof

    ten

    deci

    deto

    use

    the

    lang

    uage

    the

    syst

    emlib

    rari

    esus

    ed.A

    pplic

    atio

    nde

    velo

    pers

    use

    the

    high

    er-l

    evel

    libra

    ries

    tode

    sign

    wor

    dpr

    oces

    sors

    ,gam

    es,m

    edia

    play

    ers

    and

    the

    like.

    Man

    yof

    them

    will

    choo

    seto

    prog

    ram

    inth

    ela

    ngua

    geth

    atth

    ehi

    gher

    -lev

    ellib

    rary

    uses

    .And

    the

    patte

    rnco

    ntin

    ues

    onan

    don

    and

    on...

    ...

    12http://en.wikipedia.org/wiki/OpenGL

    13http://en.wikipedia.org/wiki/GTK

    http://en.wikipedia.org/wiki/OpenGLhttp://en.wikipedia.org/wiki/GTK

  • 1.0.

    2W

    hyC

    ,and

    nota

    noth

    erhi

    gh-le

    vell

    angu

    age?

    The

    prim

    ary

    desi

    gnof

    Cis

    topr

    oduc

    epo

    rtab

    leco

    dew

    hile

    mai

    ntai

    ning

    per-

    form

    ance

    and

    min

    imiz

    ing

    foot

    prin

    t,as

    isth

    eca

    sefo

    rop

    erat

    ing

    syst

    ems

    orot

    herp

    rogr

    ams

    whe

    rea

    "hig

    h-le

    vel"

    inte

    rfac

    ew

    ould

    affe

    ctpe

    rfor

    man

    ce.I

    tis

    ast

    able

    and

    mat

    ure

    lang

    uage

    who

    sefe

    atur

    esar

    eun

    likel

    yto

    disa

    ppea

    rfo

    ra

    long

    time

    and

    has

    been

    port

    edto

    mos

    t,if

    nota

    ll,pl

    atfo

    rms.

    Fore

    xam

    ple,

    Cpr

    ogra

    ms

    can

    beco

    mpi

    led

    and

    run

    onth

    eH

    P50

    gca

    lcul

    ator

    (AR

    Mpr

    oces

    sor)

    ,the

    TI-

    89ca

    lcul

    ator

    (680

    00pr

    oces

    sor)

    ,Pal

    mO

    SC

    obal

    tsm

    artp

    hone

    s(A

    RM

    proc

    esso

    r),t

    heor

    igin

    aliM

    ac(P

    ower

    PC),

    the

    Ard

    uino

    (Atm

    elAV

    R),

    and

    the

    Inte

    liM

    ac(I

    ntel

    Cor

    e2

    Duo

    ).W

    hile

    near

    lyal

    lpop

    ular

    prog

    ram

    min

    gla

    ngua

    ges

    will

    run

    onat

    leas

    tone

    ofth

    ese

    devi

    ces,

    Cm

    aybe

    the

    only

    prog

    ram

    min

    gla

    ngua

    geth

    atru

    nson

    mor

    eth

    an3

    ofth

    ese

    devi

    ces.

    One

    pow

    erfu

    lrea

    son

    ism

    emor

    yal

    loca

    tion.

    Unl

    ike

    mos

    tcom

    pute

    rlan

    guag

    es,

    Cal

    low

    sth

    epr

    ogra

    mm

    erto

    wri

    tedi

    rect

    lyto

    mem

    ory.

    Key

    cons

    truc

    tsin

    Csu

    chas

    stru

    cts,

    poin

    ters

    and

    arra

    ysar

    ede

    sign

    edto

    stru

    ctur

    e,an

    dm

    anip

    ulat

    em

    emor

    yin

    anef

    ficie

    nt,m

    achi

    ne-i

    ndep

    ende

    ntfa

    shio

    n.In

    part

    icul

    ar,C

    give

    s

  • cont

    rolo

    vert

    hem

    emor

    yla

    yout

    ofda

    tast

    ruct

    ures

    .Mor

    eove

    rdyn

    amic

    mem

    ory

    allo

    catio

    nis

    unde

    rth

    eco

    ntro

    lof

    the

    prog

    ram

    mer

    ,whi

    chin

    evita

    bly

    mea

    nsth

    atm

    emor

    yde

    allo

    catio

    nis

    the

    burd

    enof

    the

    prog

    ram

    mer

    .L

    angu

    ages

    like

    Java

    14an

    dPe

    rlsh

    ield

    the

    prog

    ram

    mer

    from

    havi

    ngto

    wor

    ryab

    outm

    emor

    yal

    loca

    tion

    and

    poin

    ters

    .T

    his

    isus

    ually

    ago

    odth

    ing,

    sinc

    ede

    alin

    gw

    ithm

    emor

    yal

    loca

    tion

    whe

    nbu

    ildin

    ga

    high

    -leve

    lpro

    gram

    isa

    high

    lyer

    ror-

    pron

    epr

    oces

    s.H

    owev

    er,w

    hen

    deal

    ing

    with

    low

    leve

    lcod

    esu

    chas

    the

    part

    ofth

    eO

    Sth

    atco

    ntro

    lsa

    devi

    ce,C

    prov

    ides

    aun

    iform

    ,cle

    anin

    terf

    ace.

    Thes

    eca

    pabi

    litie

    sju

    stdo

    note

    xist

    inot

    herl

    angu

    ages

    such

    asJa

    va.

    Whi

    lePe

    rl,PH

    P,Py

    thon

    and

    Rub

    ym

    aybe

    pow

    erfu

    land

    supp

    ortm

    any

    feat

    ures

    notp

    rovi

    ded

    byde

    faul

    tin

    C,t

    hey

    are

    notn

    orm

    ally

    impl

    emen

    ted

    inth

    eiro

    wn

    lang

    uage

    .Rat

    her,

    mos

    tsuc

    hla

    ngua

    ges

    initi

    ally

    relie

    don

    bein

    gw

    ritte

    nin

    C(o

    rano

    ther

    high

    -per

    form

    ance

    prog

    ram

    min

    gla

    ngua

    ge),

    and

    wou

    ldre

    quire

    thei

    rim

    plem

    enta

    tion

    bepo

    rted

    toa

    new

    plat

    form

    befo

    reth

    eyca

    nbe

    used

    .

    14http://en.wikipedia.org/wiki/Java%20%28programming%

    20language%29

    http://en.wikipedia.org/wiki/Java%20%28programming%20language%29http://en.wikipedia.org/wiki/Java%20%28programming%20language%29

  • As

    with

    all

    prog

    ram

    min

    gla

    ngua

    ges,

    whe

    ther

    you

    wan

    tto

    choo

    seC

    over

    anot

    her

    high

    -lev

    ella

    ngua

    geis

    am

    atte

    rof

    opin

    ion

    and

    both

    tech

    nica

    lan

    dbu

    sine

    ssre

    quir

    emen

    ts.

  • 2H

    isto

    ry

    The

    field

    ofco

    mpu

    ting

    asw

    ekn

    owit

    toda

    yst

    arte

    din

    1947

    with

    thre

    esc

    ient

    ists

    atB

    ellT

    elep

    hone

    Lab

    orat

    orie

    s—W

    illia

    mSh

    ockl

    ey1 ,

    Wal

    ter

    Bra

    ttain

    2 ,an

    dJo

    hnB

    arde

    en3 —

    and

    thei

    rgro

    undb

    reak

    ing

    inve

    ntio

    n:th

    etr

    ansi

    stor

    4 .In

    1956

    ,th

    efir

    stfu

    llytr

    ansi

    stor

    -bas

    edco

    mpu

    ter,

    the

    TX

    -05 ,

    was

    com

    plet

    edat

    MIT

    .

    1http://en.wikipedia.org/wiki/William%20Shockley

    2http://en.wikipedia.org/wiki/Walter%20Brattain

    3http://en.wikipedia.org/wiki/John%20Bardeen

    4http://en.wikipedia.org/wiki/transistor

    5http://en.wikipedia.org/wiki/TX-0

    11

    http://en.wikipedia.org/wiki/William%20Shockleyhttp://en.wikipedia.org/wiki/Walter%20Brattainhttp://en.wikipedia.org/wiki/John%20Bardeenhttp://en.wikipedia.org/wiki/transistorhttp://en.wikipedia.org/wiki/TX-0

  • The

    first

    inte

    grat

    edci

    rcui

    t6w

    ascr

    eate

    din

    1958

    byJa

    ckK

    ilby7

    atTe

    xas

    Inst

    rum

    ents

    ,but

    the

    first

    high

    -leve

    lpro

    gram

    min

    gla

    ngua

    geex

    iste

    dev

    enbe

    fore

    then

    .

    "The

    Fortr

    an8

    proj

    ect"

    was

    orig

    inal

    lyde

    velo

    ped

    in19

    54by

    IBM

    .Ash

    orte

    ning

    of"T

    heIB

    MM

    athe

    mat

    ical

    Form

    ula

    Tran

    slat

    ing

    Syst

    em",

    the

    proj

    ecth

    adth

    epu

    rpos

    eof

    crea

    ting

    and

    fost

    erin

    gde

    velo

    pmen

    tof

    apr

    oced

    ural

    ,im

    pera

    tive

    prog

    ram

    min

    gla

    ngua

    geth

    atw

    ases

    peci

    ally

    suite

    dto

    num

    eric

    com

    puta

    tion

    and

    scie

    ntifi

    cco

    mpu

    ting.

    Itw

    asa

    brea

    kthr

    ough

    inte

    rms

    ofpr

    oduc

    tivity

    and

    prog

    ram

    min

    gea

    se(c

    ompa

    red

    toas

    sem

    bly

    lang

    uage

    )and

    spee

    d(F

    ortr

    anpr

    ogra

    ms

    ran

    near

    lyas

    fast

    as,a

    ndin

    som

    eca

    ses,

    just

    asfa

    stas

    ,pro

    gram

    sw

    ritte

    nin

    asse

    mbl

    y).F

    urth

    erm

    ore,

    Fort

    ran

    was

    wri

    tten

    ata

    high

    -eno

    ugh

    leve

    l(a

    ndth

    usw

    asm

    achi

    nein

    depe

    nden

    teno

    ugh)

    tobe

    com

    eth

    efir

    stw

    idel

    yad

    opte

    dpr

    ogra

    mm

    ing

    lang

    uage

    .The

    Alg

    orith

    mic

    Lan

    guag

    e(A

    lgol

    589 )

    was

    deriv

    ed

    6http://en.wikipedia.org/wiki/integrated%20circuit

    7http://en.wikipedia.org/wiki/Jack%20Kilby

    8http://en.wikipedia.org/wiki/Fortran

    9http://en.wikipedia.org/wiki/ALGOL%2058

    http://en.wikipedia.org/wiki/integrated%20circuithttp://en.wikipedia.org/wiki/Jack%20Kilbyhttp://en.wikipedia.org/wiki/Fortranhttp://en.wikipedia.org/wiki/ALGOL%2058

  • from

    Fort

    ran

    in19

    58an

    dev

    olve

    din

    toA

    lgol

    6010

    in19

    60.

    The

    Com

    bine

    dPr

    ogra

    mm

    ing

    Lang

    uage

    (CPL

    )11

    was

    then

    crea

    ted

    outo

    fAlg

    ol60

    in19

    63.I

    n19

    67,i

    tevo

    lved

    into

    Bas

    icC

    PL12

    ,whi

    chw

    asits

    elf,

    the

    base

    forB

    13in

    1969

    .Fi

    nally

    ,Bw

    asth

    ero

    otof

    C,c

    reat

    edin

    1971

    .

    Bw

    asth

    efir

    stla

    ngua

    gein

    C's

    dire

    ctlin

    eage

    .Bw

    ascr

    eate

    dby

    Ken

    Tho

    mp-

    son1

    4at

    Bel

    lLab

    san

    dw

    asan

    inte

    rpre

    ted

    lang

    uage

    15us

    edin

    earl

    yin

    tern

    alve

    rsio

    nsof

    the

    UN

    IXop

    erat

    ing

    syst

    em.T

    hom

    pson

    and

    Den

    nis

    Ritc

    hie1

    6 ,al

    sow

    orki

    ngat

    Bel

    lLab

    s,im

    prov

    edB

    and

    calle

    dth

    ere

    sult

    NB

    .Fur

    ther

    exte

    nsio

    ns

    10http://en.wikipedia.org/wiki/ALGOL%2060

    11http://en.wikipedia.org/wiki/Combined%20Programming%

    20Language

    12http://en.wikipedia.org/wiki/BCPL

    13http://en.wikipedia.org/wiki/B%20%28programming%

    20language%29

    14http://en.wikipedia.org/wiki/Ken%20Thompson

    15http://en.wikipedia.org/wiki/interpreted%20language

    16http://en.wikipedia.org/wiki/Dennis%20Ritchie

    http://en.wikipedia.org/wiki/ALGOL%2060http://en.wikipedia.org/wiki/Combined%20Programming%20Languagehttp://en.wikipedia.org/wiki/Combined%20Programming%20Languagehttp://en.wikipedia.org/wiki/BCPLhttp://en.wikipedia.org/wiki/B%20%28programming%20language%29http://en.wikipedia.org/wiki/B%20%28programming%20language%29http://en.wikipedia.org/wiki/Ken%20Thompsonhttp://en.wikipedia.org/wiki/interpreted%20languagehttp://en.wikipedia.org/wiki/Dennis%20Ritchie

  • toN

    Bcr

    eate

    dits

    logi

    cals

    ucce

    ssor

    ,C,a

    com

    pile

    dla

    ngua

    ge17

    .Mos

    tofU

    NIX

    was

    rew

    ritte

    nin

    NB

    ,and

    then

    C,w

    hich

    resu

    lted

    ina

    mor

    epo

    rtab

    leop

    erat

    ing

    syst

    em.

    The

    port

    abili

    tyof

    UN

    IXw

    asth

    em

    ain

    reas

    onfo

    rth

    ein

    itial

    popu

    lari

    tyof

    both

    UN

    IXan

    dC

    .Rat

    hert

    han

    crea

    ting

    ane

    wop

    erat

    ing

    syst

    emfo

    reac

    hne

    wm

    achi

    ne,s

    yste

    mpr

    ogra

    mm

    ers

    coul

    dsi

    mpl

    yw

    rite

    the

    few

    syst

    em-d

    epen

    dent

    parts

    requ

    ired

    fort

    hem

    achi

    ne,a

    ndth

    enw

    rite

    aC

    com

    pile

    rfor

    the

    new

    syst

    em.

    Sinc

    em

    osto

    fthe

    syst

    emut

    ilitie

    sw

    ere

    thus

    writ

    ten

    inC

    ,its

    impl

    ym

    ade

    sens

    eto

    also

    wri

    tene

    wut

    ilitie

    sin

    C.

    The

    Am

    eric

    anN

    atio

    nalS

    tand

    ards

    Inst

    itute

    bega

    nw

    ork

    onst

    anda

    rdiz

    ing

    the

    Cla

    ngua

    gein

    1983

    ,an

    dco

    mpl

    eted

    the

    stan

    dard

    in19

    89.

    The

    stan

    dard

    ,A

    NSI

    X3.

    159-

    1989

    "Pro

    gram

    min

    gL

    angu

    age

    C",

    serv

    edas

    the

    basi

    sfo

    ral

    lim

    plem

    enta

    tions

    ofC

    com

    pile

    rs.T

    hest

    anda

    rds

    wer

    ela

    teru

    pdat

    edin

    1990

    and

    1999

    ,allo

    win

    gfo

    rfea

    ture

    sth

    atw

    ere

    eith

    erin

    com

    mon

    use,

    orw

    ere

    appe

    arin

    gin

    C++

    .

    17http://en.wikipedia.org/wiki/compiled%20language

    http://en.wikipedia.org/wiki/compiled%20language

  • 3W

    haty

    oune

    edbe

    fore

    you

    can

    lear

    n

    3.1

    Get

    ting

    Star

    ted

    The

    goal

    ofth

    isbo

    okis

    toin

    trod

    uce

    you

    toth

    eC

    prog

    ram

    min

    gla

    ngua

    ge.

    Bas

    icco

    mpu

    terl

    itera

    cyis

    assu

    med

    ,but

    nosp

    ecia

    lkno

    wle

    dge

    isne

    eded

    .

    The

    min

    imum

    soft

    war

    ere

    quir

    emen

    tsto

    prog

    ram

    inC

    isa

    text

    edito

    r1,a

    sop

    pose

    dto

    aw

    ord

    proc

    esso

    r2.T

    here

    are

    man

    yte

    xted

    itors

    (see

    Lis

    tofT

    ext

    1http://en.wikipedia.org/wiki/text%20editor

    2http://en.wikipedia.org/wiki/word%20processor

    15

    http://en.wikipedia.org/wiki/text%20editorhttp://en.wikipedia.org/wiki/word%20processor

  • Edi

    tors

    3 ),t

    hem

    ostp

    opul

    arbe

    ing

    vi4 ,

    itscl

    ones

    (suc

    has

    Vim

    5 ),a

    ndE

    mac

    s6.

    Ate

    xted

    itorw

    ithsy

    ntax

    high

    light

    ing7

    isre

    com

    men

    ded,

    asit

    can

    mak

    eco

    deea

    sier

    tore

    adat

    agl

    ance

    .H

    ighl

    ight

    ing

    can

    also

    mak

    eit

    easy

    tosp

    otsy

    ntax

    erro

    rs.M

    ostp

    rogr

    amm

    ers'

    text

    edito

    rson

    Win

    dow

    san

    dU

    nix

    syst

    ems

    can

    doth

    is.

    Ifyo

    uch

    oose

    tous

    ea

    text

    edito

    r,yo

    uw

    illbe

    requ

    ired

    toha

    vea

    Cco

    mpi

    ler.

    Aco

    mpi

    leri

    sa

    prog

    ram

    that

    conv

    erts

    Cco

    dein

    toex

    ecut

    able

    mac

    hine

    code

    8 .9

    Popu

    lar

    Cco

    mpi

    lers

    Incl

    ude:

    3http://en.wikipedia.org/wiki/List%20of%20text%20editors

    4http://en.wikipedia.org/wiki/vi

    5http://en.wikipedia.org/wiki/Vim%20%28text%20editor%29

    6http://en.wikipedia.org/wiki/Emacs

    7http://en.wikipedia.org/wiki/syntax%20highlighting

    8http://en.wikipedia.org/wiki/machine%20code

    9A

    ctua

    lly,G

    CC

    's(G

    NU

    CC

    ompi

    ler)

    cc(C

    Com

    pile

    r)tr

    ansl

    ates

    the

    inpu

    t.c

    file

    toth

    eta

    rget

    cpu'

    sas

    sem

    bly,

    outp

    utis

    wri

    tten

    toan

    .sfil

    e.T

    hen

    as(a

    ssem

    bler

    )ge

    nera

    tes

    am

    achi

    neco

    defil

    efr

    omth

    e.s

    file.

    Pre-

    proc

    essi

    ngis

    done

    byan

    othe

    rsub

    -pro

    gram

    cpp

    (CPr

    ePro

    cess

    or).

    http://en.wikipedia.org/wiki/List%20of%20text%20editorshttp://en.wikipedia.org/wiki/vihttp://en.wikipedia.org/wiki/Vim%20%28text%20editor%29http://en.wikipedia.org/wiki/Emacshttp://en.wikipedia.org/wiki/syntax%20highlightinghttp://en.wikipedia.org/wiki/machine%20code

  • Plat

    form

    Lic

    ense

    Ext

    raC

    /C++

    inte

    rpre

    ter

    Ch1

    0

    soft

    inte

    gra-

    tion1

    1W

    indo

    ws,

    Lin

    ux,

    Mac

    OSX

    ,Fr

    eeB

    SD,

    Sola

    ris,

    AIX

    ,QN

    X,

    HP-

    UX

    Ch

    Stan

    dard

    Edi

    tion

    isfr

    eefo

    rco

    mm

    erci

    alus

    e

    user

    frie

    ndly

    fort

    hebe

    ginn

    ers

    Ope

    nWat

    -co

    m12

    open

    wat

    -co

    m13

    DO

    S,W

    in-

    dow

    s,N

    et-

    war

    e,O

    S/2

    Ope

    nso

    urce

    Bor

    land

    CC

    ompi

    ler

    cpp-

    build

    er14

    Win

    dow

    sFr

    eew

    are

    10http://en.wikipedia.org/wiki/Ch%20interpreter

    11http://www.softintegration.com

    12http://en.wikipedia.org/wiki/Openwatcom

    13http://openwatcom.org

    14http://www.codegear.com/downloads/free/cppbuilder

    http://en.wikipedia.org/wiki/Ch%20interpreterhttp://www.softintegration.comhttp://en.wikipedia.org/wiki/Openwatcomhttp://openwatcom.orghttp://www.codegear.com/downloads/free/cppbuilder

  • Plat

    form

    Lic

    ense

    Ext

    raM

    icro

    soft

    Vis

    ualS

    tu-

    dio

    Ex-

    pres

    s15

    vstu

    dio1

    6W

    indo

    ws

    Free

    war

    elig

    ht-w

    eigh

    t,po

    wer

    ful,

    and

    stud

    ent-

    frie

    ndly

    vers

    ion

    ofan

    indu

    stry

    stan

    dard

    com

    pile

    rTi

    nyC

    Com

    pile

    r(T

    CC

    )17

    tinyc

    c18

    GN

    U/L

    inux

    ,W

    indo

    ws

    LG

    PL19

    Smal

    l,fa

    st,

    new

    com

    er-

    frie

    ndly

    com

    pile

    r.

    15http://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%

    20Express

    16http://www.msdn.microsoft.com/vstudio/express/beginner

    17http://en.wikipedia.org/wiki/Tiny%20C%20Compiler

    18http://www.tinycc.org

    19http://en.wikipedia.org/wiki/GNU%20Lesser%20General%

    20Public%20License

    http://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%20Expresshttp://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%20Expresshttp://www.msdn.microsoft.com/vstudio/express/beginnerhttp://en.wikipedia.org/wiki/Tiny%20C%20Compilerhttp://www.tinycc.orghttp://en.wikipedia.org/wiki/GNU%20Lesser%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20Lesser%20General%20Public%20License

  • Plat

    form

    Lic

    ense

    Ext

    raG

    NU

    CC

    ompi

    ler2

    0gc

    c21

    DO

    S22 ,

    Cyg

    win

    (w32

    )23 ,

    Min

    GW

    (w32

    )24 ,

    OS/

    225 ,

    Mac

    OS

    X,U

    nix,

    GPL

    26D

    efa

    cto

    stan

    dard

    .Sh

    ips

    with

    mos

    tUni

    xsy

    stem

    s.

    Tho

    ugh

    not

    abso

    lute

    lyne

    eded

    ,man

    ypr

    ogra

    mm

    ers

    pref

    eran

    dre

    com

    men

    dus

    ing

    anIn

    tegr

    ated

    deve

    lopm

    ente

    nvir

    onm

    ent2

    7(I

    DE

    )ins

    tead

    ofa

    text

    edito

    r

    20http://en.wikipedia.org/wiki/GNU%20Compiler%20Collection

    21http://gcc.gnu.org

    22http://delorie.com/djgpp/

    23http://cygwin.com/

    24http://mingw.org/

    25http://www.edm2.com/0101/emx.html

    26http://en.wikipedia.org/wiki/GNU%20General%20Public%

    20License

    27http://en.wikipedia.org/wiki/Integrated%20development%

    20environment

    http://en.wikipedia.org/wiki/GNU%20Compiler%20Collectionhttp://gcc.gnu.orghttp://delorie.com/djgpp/http://cygwin.com/http://mingw.org/http://www.edm2.com/0101/emx.htmlhttp://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/Integrated%20development%20environmenthttp://en.wikipedia.org/wiki/Integrated%20development%20environment

  • and

    com

    pile

    r.A

    nID

    Eis

    asu

    iteof

    prog

    ram

    sth

    atde

    velo

    pers

    need

    ,com

    bine

    din

    toon

    eco

    nven

    ient

    pack

    age,

    usua

    llyw

    itha

    grap

    hica

    luse

    rin

    terf

    ace.

    The

    sepr

    ogra

    ms

    incl

    ude

    aco

    mpi

    ler,

    linke

    r,an

    dte

    xted

    itor.

    The

    yty

    pica

    llyin

    clud

    ea

    debu

    gger

    ,ato

    olth

    atw

    illpr

    eser

    veyo

    urC

    sour

    ceco

    deaf

    terc

    ompi

    latio

    nan

    den

    able

    you

    todo

    such

    thin

    gsas

    step

    thro

    ugh

    itm

    anua

    lly,o

    ralte

    rdat

    aas

    anai

    dto

    findi

    ngan

    dco

    rrec

    ting

    prog

    ram

    min

    ger

    rors

    .

    Popu

    lar

    IDE

    sInc

    lude

    :

  • Plat

    form

    Lic

    ense

    Ext

    ra

    Plat

    form

    Lic

    ense

    Ext

    raC

    DT

    cdt2

    8W

    in-

    dow

    s,M

    acO

    SX

    ,Uni

    x

    Ope

    nso

    urce

    AC

    /C++

    plug

    -in

    for

    Ecl

    ipse

    29,

    apo

    pula

    rop

    enso

    urce

    IDE

    .

    28http://eclipse.org/cdt

    29http://en.wikipedia.org/wiki/Eclipse%20%28computing%29

    http://eclipse.org/cdthttp://en.wikipedia.org/wiki/Eclipse%20%28computing%29

  • Plat

    form

    Lic

    ense

    Ext

    raA

    njut

    a30

    An-

    juta

    31U

    nix

    GPL

    32A GT

    K+2

    IDE

    fort

    heG

    NO

    ME3

    3

    desk

    top

    envi

    ron-

    men

    t

    30http://en.wikipedia.org/wiki/Anjuta

    31http://anjuta.org

    32http://en.wikipedia.org/wiki/GNU%20General%20Public%

    20License

    33http://en.wikipedia.org/wiki/GNOME

    http://en.wikipedia.org/wiki/Anjutahttp://anjuta.orghttp://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNOME

  • Plat

    form

    Lic

    ense

    Ext

    raG

    eany

    34ge

    any3

    5C

    ross

    -pl

    atfo

    rmG

    PL36

    A light

    wei

    ght

    cros

    s-pl

    atfo

    rmG

    TK

    +ID

    Eba

    sed

    onSc

    intil

    la

    34http://en.wikipedia.org/wiki/Geany

    35http://www.geany.org/

    36http://en.wikipedia.org/wiki/GNU%20General%20Public%

    20License

    http://en.wikipedia.org/wiki/Geanyhttp://www.geany.org/http://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20General%20Public%20License

  • Plat

    form

    Lic

    ense

    Ext

    raL

    ittle

    CC

    ompi

    ler

    (LC

    C)3

    7

    lcc3

    8W

    in-

    dow

    sFr

    eefo

    rnon

    -co

    mm

    erci

    alus

    e.

    37http://en.wikipedia.org/wiki/LCC%20%28compiler%29

    38http://www.cs.virginia.edu/~lcc-win32

    http://en.wikipedia.org/wiki/LCC%20%28compiler%29http://www.cs.virginia.edu/~lcc-win32

  • Plat

    form

    Lic

    ense

    Ext

    raX

    code

    39xc

    ode4

    0M

    acO

    SX

    Free

    Ava

    il-ab

    leas

    dow

    n-lo

    adw

    hen

    reg-

    iste

    red

    (pai

    d)at

    Ap-

    ple

    De-

    velo

    per

    Con

    nec-

    tion4

    1or

    toth

    ose

    with

    out

    App

    leD

    evel

    -op

    erC

    on-

    nect

    ion

    subs

    crip

    -tio

    nsat

    Mac

    App

    Stor

    e42 .

    39http://en.wikipedia.org/wiki/Xcode

    http://en.wikipedia.org/wiki/Xcode

  • Plat

    form

    Lic

    ense

    Ext

    raPe

    lles

    C43

    Pelle

    sC

    44W

    in-

    dow

    s,Po

    cket

    PC

    "fre

    e"

    40http://developer.apple.com/tools/xcode

    41http://developer.apple.com/

    42http://itunes.apple.com/us/app/xcode/id448457090/

    43http://en.wikipedia.org/wiki/Pelles%20C

    44http://smorgasbordet.com/pellesc/

    http://developer.apple.com/tools/xcodehttp://developer.apple.com/http://itunes.apple.com/us/app/xcode/id448457090/http://en.wikipedia.org/wiki/Pelles%20Chttp://smorgasbordet.com/pellesc/

  • Plat

    form

    Lic

    ense

    Ext

    raD

    evC

    ++45

    Dev

    C++

    46W

    in-

    dow

    s,L

    inux

    (alp

    have

    rsio

    non

    ly)

    GPL

    47

    45http://en.wikipedia.org/wiki/Dev%20C%2B%2B%20

    46http://www.bloodshed.net/devcpp.html

    47http://en.wikipedia.org/wiki/GNU%20General%20Public%

    20License

    http://en.wikipedia.org/wiki/Dev%20C%2B%2B%20http://www.bloodshed.net/devcpp.htmlhttp://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20General%20Public%20License

  • Plat

    form

    Lic

    ense

    Ext

    raM

    i-cr

    osof

    tV

    isua

    lSt

    u-di

    oE

    x-pr

    ess4

    8

    Vis

    ual

    Stu-

    dio

    Ex-

    pres

    s49

    Win

    -do

    ws

    Free

    light

    wei

    ght,

    pow

    erfu

    l,st

    uden

    tfr

    iend

    lyve

    rsio

    nof

    anin

    dust

    ryst

    anda

    rdco

    mpi

    ler

    48http://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%

    20Express

    49http://www.msdn.microsoft.com/vstudio/express/beginner

    http://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%20Expresshttp://en.wikipedia.org/wiki/Microsoft%20Visual%20Studio%20Expresshttp://www.msdn.microsoft.com/vstudio/express/beginner

  • Plat

    form

    Lic

    ense

    Ext

    raC

    ode:

    :Blo

    cks5

    0 Cod

    e::B

    lock

    s51

    Win

    -do

    ws,

    Lin

    ux,

    Mac

    OS

    X

    GPL

    52

    3.0

    Bui

    ltto

    mee

    tus

    ers'

    mos

    tde-

    man

    ding

    need

    s.V

    ery

    ex-

    tens

    ible

    and

    fully

    confi

    g-ur

    able

    .

    On

    GN

    U/L

    INU

    X,G

    CC

    isal

    mos

    talw

    ays

    incl

    uded

    auto

    mat

    ical

    ly.

    50http://en.wikipedia.org/wiki/Code%3A%3ABlocks

    51http://www.codeblocks.org/

    52http://en.wikipedia.org/wiki/GNU%20General%20Public%

    20License

    http://en.wikipedia.org/wiki/Code%3A%3ABlockshttp://www.codeblocks.org/http://en.wikipedia.org/wiki/GNU%20General%20Public%20Licensehttp://en.wikipedia.org/wiki/GNU%20General%20Public%20License

  • On

    Mic

    roso

    ftW

    indo

    ws,

    Dev

    -C++

    isre

    com

    men

    ded

    forb

    egin

    ners

    beca

    use

    itis

    easy

    tous

    e,fr

    ee,a

    ndsi

    mpl

    eto

    inst

    all.

    How

    ever

    ,the

    offic

    ialr

    elea

    seof

    Dev

    -C++

    hasn

    'tbe

    enup

    date

    dsi

    nce

    22Fe

    brua

    ry20

    05.5

    3A

    nun

    offic

    ialv

    ersi

    onof

    Dev

    -C

    ++is

    bein

    gac

    tivel

    yde

    velo

    ped

    how

    ever

    .54

    An

    alte

    rnat

    eop

    tion,

    Mic

    roso

    ftV

    isua

    lStu

    dio

    Exp

    ress

    ,may

    also

    behe

    lpfu

    lfor

    begi

    nner

    sbu

    treq

    uire

    sse

    tting

    upa

    com

    pila

    tion

    proj

    ectb

    efor

    em

    akin

    gan

    exec

    utab

    lefil

    e.

    On

    Mac

    OS

    X,t

    heX

    code

    IDE

    prov

    ides

    the

    com

    pile

    rsne

    eded

    toco

    mpi

    leva

    rious

    sour

    cefil

    es.I

    nsta

    lling

    Xco

    dein

    stal

    lsbo

    thth

    eco

    mm

    and-

    line

    com

    pile

    rsas

    wel

    las

    the

    grap

    hica

    lID

    E.

    3.2

    Foot

    note

    s

    pl:C

    /Cze

    gopo

    trze

    buje

    sz55

    53http://sourceforge.net/news/?group_id=10639

    54http://orwellengine.blogspot.com/

    55http://pl.wikibooks.org/wiki/C%2FCzego%20potrzebujesz

    http://sourceforge.net/news/?group_id=10639http://orwellengine.blogspot.com/http://pl.wikibooks.org/wiki/C%2FCzego%20potrzebujesz

  • 4U

    sing

    aC

    ompi

    ler

    4.0.

    1D

    ev-C

    ++

    Dev

    C++

    1is

    anIn

    tegr

    ated

    Dev

    elop

    men

    tE

    nvir

    onm

    ent(

    IDE

    )fo

    rth

    eC

    ++pr

    ogra

    mm

    ing

    lang

    uage

    ,ava

    ilabl

    efr

    omB

    lood

    shed

    Soft

    war

    e2.

    C++

    isa

    prog

    ram

    min

    gla

    ngua

    gew

    hich

    cont

    ains

    with

    inits

    elf,

    mos

    toft

    heC

    lang

    uage

    ,plu

    sex

    tens

    ions

    .M

    ost

    C++

    com

    pile

    rsw

    illco

    mpi

    leC

    prog

    ram

    s,

    1http://en.wikipedia.org/wiki/Dev-C%20Plus%20Plus

    2http://www.bloodshed.net/

    31

    http://en.wikipedia.org/wiki/Dev-C%20Plus%20Plushttp://www.bloodshed.net/

  • som

    etim

    esw

    itha

    few

    adju

    stm

    ents

    (lik

    ein

    voki

    ngth

    emw

    itha

    diff

    eren

    tnam

    eor

    com

    man

    dlin

    esw

    itch)

    .The

    refo

    re,y

    ouca

    nus

    eD

    evC

    ++fo

    rCde

    velo

    pmen

    t.

    How

    ever

    ,Dev

    C++

    isno

    tthe

    com

    pile

    r.It

    isde

    sign

    edto

    use

    the

    Min

    GW

    3or

    Cyg

    win

    4ve

    rsio

    nsof

    GC

    C5

    -bot

    hof

    whi

    chca

    nbe

    obta

    ined

    aspa

    rtof

    the

    Dev

    C++

    pack

    age,

    alth

    ough

    they

    are

    com

    plet

    ely

    diff

    eren

    tpro

    ject

    s.

    Dev

    C++

    sim

    ply

    prov

    ides

    aned

    itor,

    synt

    axhi

    ghlig

    htin

    g,so

    me

    faci

    litie

    sfo

    rth

    evi

    sual

    isat

    ion

    ofco

    de(l

    ike

    clas

    san

    dpa

    ckag

    ebr

    owsi

    ng)

    and

    agr

    aphi

    cal

    inte

    rfac

    eto

    the

    chos

    enco

    mpi

    ler.

    Bec

    ause

    Dev

    C++

    anal

    yses

    the

    erro

    rmes

    sage

    spr

    oduc

    edby

    the

    com

    pile

    rand

    atte

    mpt

    sto

    dist

    ingu

    ish

    the

    line

    num

    bers

    from

    the

    erro

    rsth

    emse

    lves

    ,the

    use

    ofot

    herc

    ompi

    lers

    oftw

    are

    isdi

    scou

    rage

    dsi

    nce

    the

    form

    atof

    thei

    rerr

    orm

    essa

    ges

    islik

    ely

    tobe

    diff

    eren

    t.

    3http://en.wikipedia.org/wiki/MinGW

    4http://en.wikipedia.org/wiki/Cygwin

    5http://en.wikipedia.org/wiki/GCC

    http://en.wikipedia.org/wiki/MinGWhttp://en.wikipedia.org/wiki/Cygwinhttp://en.wikipedia.org/wiki/GCC

  • The

    late

    stve

    rsio

    nof

    Dev

    -C++

    isa

    beta

    6fo

    rver

    sion

    5.H

    owev

    er,i

    tstil

    lhas

    asi

    gnifi

    cant

    num

    bero

    fbug

    s.A

    llth

    efe

    atur

    esar

    eth

    ere,

    and

    itis

    quite

    usab

    le.I

    tis

    cons

    ider

    edon

    eof

    the

    best

    free

    soft

    war

    eC

    IDE

    sav

    aila

    ble

    forW

    indo

    ws.

    Ave

    rsio

    nof

    Dev

    C++

    forL

    inux

    isin

    the

    pipe

    line.

    Itis

    notq

    uite

    usab

    leye

    t,ho

    wev

    er.L

    inux

    user

    salre

    ady

    have

    aw

    ealth

    ofID

    Esav

    aila

    ble.

    (e.g

    .KD

    evel

    op7

    and

    Anj

    uta8

    .)M

    osto

    fth

    egr

    aphi

    calt

    exte

    dito

    rs,a

    ndot

    her

    com

    mon

    edito

    rssu

    chas

    emac

    san

    dvi

    (m),

    supp

    orts

    ynta

    xhi

    ghlig

    htin

    g9.

    6http://en.wikipedia.org/wiki/beta%20version

    7http://en.wikipedia.org/wiki/KDevelop

    8http://en.wikipedia.org/wiki/Anjuta

    9http://en.wikipedia.org/wiki/syntax%20highlighting

    http://en.wikipedia.org/wiki/beta%20versionhttp://en.wikipedia.org/wiki/KDevelophttp://en.wikipedia.org/wiki/Anjutahttp://en.wikipedia.org/wiki/syntax%20highlighting

  • 4.0.

    2G

    CC

    The

    GN

    UC

    ompi

    lerC

    olle

    ctio

    n10

    (GC

    C)i

    sa

    free

    11se

    tofc

    ompi

    lers

    deve

    lope

    dby

    the

    Free

    Soft

    war

    eFo

    unda

    tion1

    2 .

    Step

    sfor

    Obt

    aini

    ngth

    eG

    CC

    Com

    pile

    rif

    You'

    reon

    GN

    U/L

    inux

    On

    GN

    U/L

    inux

    ,Ins

    talli

    ngth

    eG

    NU

    CC

    ompi

    ler

    can

    vary

    inm

    etho

    dfr

    omdi

    stri

    butio

    n13

    todi

    stri

    butio

    n.

    •Fo

    rR

    edha

    t14 ,

    geta

    GC

    CR

    PM15

    ,e.g

    .us

    ing

    Rpm

    find

    and

    then

    inst

    all(

    asro

    ot)u

    sing

    rpm-ivhgcc-version-release.arch.rpm

    10http://en.wikipedia.org/wiki/GNU%20Compiler%20Collection

    11http://en.wikipedia.org/wiki/free%20software

    12http://en.wikipedia.org/wiki/Free%20Software%20Foundation

    13http://en.wikipedia.org/wiki/Linux%20distribution

    14http://en.wikipedia.org/wiki/Redhat

    15http://en.wikipedia.org/wiki/RPM%20Package%20Manager

    http://en.wikipedia.org/wiki/GNU%20Compiler%20Collectionhttp://en.wikipedia.org/wiki/free%20softwarehttp://en.wikipedia.org/wiki/Free%20Software%20Foundationhttp://en.wikipedia.org/wiki/Linux%20distributionhttp://en.wikipedia.org/wiki/Redhathttp://en.wikipedia.org/wiki/RPM%20Package%20Manager

  • •Fo

    rFe

    dora

    Cor

    e16 ,

    inst

    all

    the

    GC

    Cco

    mpi

    ler

    (as

    root

    )by

    usin

    gyum17

    installgcc

    .•

    For

    Man

    drak

    e18 ,

    inst

    all

    the

    GC

    Cco

    mpi

    ler

    (as

    root

    )by

    usin

    gurpmi19

    gcc

    •Fo

    rD

    ebia

    n20 ,

    inst

    all

    the

    GC

    Cco

    mpi

    ler

    (as

    root

    )by

    usin

    gapt-get21

    installgcc

    .•

    ForU

    bunt

    u22 ,

    inst

    allt

    heG

    CC

    com

    pile

    r(al

    ong

    with

    othe

    rnec

    essa

    ryto

    ols)

    byus

    ingsudoapt-get23installbuild-essential

    ,orb

    yus

    ing

    Syna

    ptic

    .You

    dono

    tnee

    dU

    nive

    rse

    enab

    led.

    16http://en.wikipedia.org/wiki/Fedora%20Core

    17http://en.wikipedia.org/wiki/yum

    18http://en.wikipedia.org/wiki/Mandrake

    19http://en.wikipedia.org/wiki/urpmi

    20http://en.wikipedia.org/wiki/Debian

    21http://en.wikipedia.org/wiki/Advanced%20Packaging%20Tool

    22http://en.wikipedia.org/wiki/Ubuntu

    23http://en.wikipedia.org/wiki/Advanced%20Packaging%20Tool

    http://en.wikipedia.org/wiki/Fedora%20Corehttp://en.wikipedia.org/wiki/yumhttp://en.wikipedia.org/wiki/Mandrakehttp://en.wikipedia.org/wiki/urpmihttp://en.wikipedia.org/wiki/Debianhttp://en.wikipedia.org/wiki/Advanced%20Packaging%20Toolhttp://en.wikipedia.org/wiki/Ubuntuhttp://en.wikipedia.org/wiki/Advanced%20Packaging%20Tool

  • •Fo

    rSla

    ckw

    are2

    4 ,th

    epa

    ckag

    eis

    avai

    labl

    eon

    thei

    rw

    ebsi

    te25

    -sim

    ply

    dow

    n-lo

    ad,a

    ndty

    peinstallpkggcc-xxxxx.tgz

    •Fo

    rGen

    too2

    6 ,yo

    ush

    ould

    alre

    ady

    have

    GC

    Cin

    stal

    led

    asit

    will

    have

    been

    used

    whe

    nyo

    ufir

    stin

    stal

    led.

    Toup

    date

    itru

    n(a

    sro

    ot)emerge-uav

    gcc

    .•

    ForA

    rch

    Linu

    x27 ,

    inst

    allt

    heG

    CC

    com

    pile

    r(as

    root

    )by

    usin

    gpacman-S

    gcc

    .•

    Ifyo

    uca

    nnot

    beco

    me

    root

    ,get

    the

    GC

    Cta

    rbal

    lfro

    mft

    p://f

    tp.g

    nu.o

    rg/a

    ndfo

    llow

    the

    inst

    ruct

    ions

    init

    toco

    mpi

    lean

    din

    stal

    lin

    your

    hom

    edi

    rect

    ory.

    Be

    war

    ned

    thou

    gh,y

    oune

    eda

    Cco

    mpi

    ler

    todo

    that

    -ye

    s,G

    CC

    itsel

    fis

    wri

    tten

    inC

    .•

    You

    can

    use

    som

    eco

    mm

    erci

    alC

    com

    pile

    r/ID

    E.

    Step

    sfor

    Obt

    aini

    ngth

    eGC

    CC

    ompi

    leri

    fYou

    'reo

    nB

    SDFa

    mily

    Syst

    ems

    24http://en.wikipedia.org/wiki/Slackware

    25http://www.slackware.com/pb/

    26http://en.wikipedia.org/wiki/Gentoo

    27http://en.wikipedia.org/wiki/Arch%20Linux

    http://en.wikipedia.org/wiki/Slackwarehttp://www.slackware.com/pb/http://en.wikipedia.org/wiki/Gentoohttp://en.wikipedia.org/wiki/Arch%20Linux

  • •Fo

    rMac

    OS

    X28

    ,Fre

    eBSD

    29,N

    etB

    SD30

    ,Ope

    nBSD

    31,D

    rago

    nFly

    BSD

    32,

    Dar

    win

    33th

    epo

    rtof

    GN

    Ugc

    cis

    avai

    labl

    ein

    the

    base

    syst

    em,o

    ritc

    ould

    beob

    tain

    edus

    ing

    the

    port

    sco

    llect

    ion

    orpk

    gsrc

    34.

    Step

    sfor

    Obt

    aini

    ngth

    eG

    CC

    Com

    pile

    rif

    You'

    reon

    Win

    dow

    s

    The

    rear

    etw

    ow

    ays

    tous

    eG

    CC

    onW

    indo

    ws:

    Cyg

    win

    and

    Min

    GW

    .App

    lica-

    tions

    com

    pile

    dw

    ithC

    ygw

    inw

    illno

    trun

    onan

    yco

    mpu

    ter

    with

    outC

    ygw

    in,

    soM

    inG

    Wis

    reco

    mm

    ende

    d.M

    inG

    Wis

    sim

    pler

    toin

    stal

    l,an

    dta

    kes

    less

    disk

    spac

    e.

    Toge

    tMin

    GW

    ,do

    this

    :

    28http://en.wikipedia.org/wiki/Mac%20OS%20X

    29http://en.wikipedia.org/wiki/FreeBSD

    30http://en.wikipedia.org/wiki/NetBSD

    31http://en.wikipedia.org/wiki/OpenBSD

    32http://en.wikipedia.org/wiki/DragonFly%20BSD

    33http://en.wikipedia.org/wiki/Darwin

    34http://en.wikipedia.org/wiki/pkgsrc

    http://en.wikipedia.org/wiki/Mac%20OS%20Xhttp://en.wikipedia.org/wiki/FreeBSDhttp://en.wikipedia.org/wiki/NetBSDhttp://en.wikipedia.org/wiki/OpenBSDhttp://en.wikipedia.org/wiki/DragonFly%20BSDhttp://en.wikipedia.org/wiki/Darwinhttp://en.wikipedia.org/wiki/pkgsrc

  • 1.G

    oto

    http

    ://so

    urce

    forg

    e.ne

    t/pro

    ject

    s/m

    ingw

    /35

    dow

    nloa

    dan

    dsa

    veth

    isto

    your

    hard

    driv

    e.2.

    Onc

    eth

    edo

    wnl

    oad

    isfin

    ishe

    d,op

    enit

    and

    follo

    wth

    ein

    stru

    ctio

    ns.Y

    ouca

    nal

    soch

    oose

    toin

    stal

    ladd

    ition

    alco

    mpi

    lers

    ,or

    the

    tool

    Mak

    e,bu

    tth

    ese

    aren

    'tne

    cess

    ary.

    3.N

    owyo

    une

    edto

    sety

    our

    PAT

    H.R

    ight

    -clic

    kon

    "My

    com

    pute

    r"an

    dcl

    ick

    "Pro

    perti

    es".

    Go

    toth

    e"A

    dvan

    ced"

    tab

    and

    clic

    kon

    "Env

    ironm

    ent

    vari

    able

    s".G

    oto

    the

    "Sys

    tem

    vari

    able

    s"se

    ctio

    nan

    dsc

    roll

    dow

    nun

    tilyo

    use

    e"P

    ath"

    .C

    lick

    onit,

    then

    clic

    k"e

    dit"

    .A

    dd";

    C:\m

    ingw

    \bin

    \"(w

    ithou

    tthe

    quot

    es)t

    oth

    een

    d.4.

    Tote

    stif

    GC

    Cw

    orks

    ,ope

    na

    com

    man

    dpr

    ompt

    and

    type

    "gcc

    ".Y

    oush

    ould

    gett

    hem

    essa

    ge"g

    cc:

    noin

    putfi

    les"

    .If

    you

    gett

    his

    mes

    sage

    ,G

    CC

    isin

    stal

    led

    corr

    ectly

    .

    Toge

    tCyg

    win

    ,do

    this

    :

    35http://sourceforge.net/projects/mingw/

    http://sourceforge.net/projects/mingw/

  • 1.G

    oto

    http

    ://w

    ww

    .cyg

    win

    .com

    36an

    dcl

    ick

    onth

    e"I

    nsta

    llC

    ygw

    inN

    ow"

    butto

    nin

    the

    uppe

    rrig

    htco

    rner

    ofth

    epa

    ge.

    2.C

    lick

    "run

    "in

    the

    win

    dow

    that

    pops

    up,a

    ndcl

    ick

    "nex

    t"se

    vera

    ltim

    es,

    acce

    ptin

    gal

    lthe

    defa

    ults

    ettin

    gs.

    3.C

    hoos

    ean

    yof

    the

    Dow

    nloa

    dsi

    tes

    ("ft

    p.ea

    syne

    t.be"

    ,etc

    .)w

    hen

    that

    win

    dow

    com

    esup

    ;pre

    ss"n

    ext"

    and

    the

    Cyg

    win

    inst

    alle

    rsh

    ould

    star

    tdo

    wnl

    oadi

    ng.

    4.W

    hen

    the

    "Sel

    ectP

    acka

    ges"

    win

    dow