3  C++
This presentation is the property of its rightful owner.
Sponsored Links
1 / 78

3 C++ 语言基础 PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on
  • Presentation posted in: General

3 C++ 语言基础. 3.1 标识符 标识符( identifier )在程序中可以作为不同类型数据或函数的名字。常见的有: 变量( variable )、结构( struct )、联合( union )、枚举( enum )、函数( function )、类( class )和对象( object )等。 C++ 标识符由大、小写字母、数字和下划线组成,并只能以字母或下划线开始。.

Download Presentation

3 C++ 语言基础

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3 c

3 C++

  • 3.1

  • identifiervariablestructunionenumfunctionclassobject

  • C++


3 c

  • C++keywordCasmautoboolbreakcasechardefaultdoexternfalsefloatgotoifintlongtruewhileC++classcatchdeletefriendpublicnewprivateprotectedvirtualtemplate


3 c

  • 3.2

3.1 C++


3 c

  • 3.2.1

  • C++charintegerfloatvoid

  • 3.2.2

  • 1typedef

  • typedef

    typedef int Integer//Integerint

    Integer x//xInteger int


3 c

  • 2struct

  • Struct {

    1 1


3 c

2 2

n n

}

struct date{

int year;

int month;

int day;

};

date my_date;

my_date.year1980


3 c

  • 3union


3 c

union{

1 1

2 2

n n

}

union data{

int i;

char ch;


3 c

u1;

u11

u1A;

  • 3.2.3

  • 1

  • C++doublefloatlongintshort

  • 2


3 c

  • C++

  • 3.3

  • 3.3.1

  • C++void


3 c

  • 1

  • []

  • n0n-1


3 c

  • C++

  • C++0n-1

  • int n10;

    int a [n];


3 c

  • 2

  • [1][2][n]

  • 12


3 c

int array[2] [3]{012345}

  • array[0] [0]0, array[0] [1]1,

    array[0] [2]2, array[1] [0]3,

    array[1] [1]4, array[1] [2]5

  • 0

    int array[2] [3]{012}


3 c

array[0] [0]0, array[0] [1]1,

array[0] [2]2,

array[1] [0]0, array[1] [1]0,

array[1] [2]0

  • int array[2] [3]{012,345}

  • 3.3.2

  • C++C++


3 c

  • \0

  • 3.3.3

  • 1

  • C++C++

    *

  • C++*

    int *p1,*p2;


3 c

  • p1p2

  • &

  • *

  • & aa*pp


3 c

  • 0NULL

  • 4


3 c

  • int a,*p1,*p2;

    p1&a

    p2p1//p2p1 p2p1a

  • 11


3 c

  • CC++newdelete


3 c

ptr1=new type; //ptr1type

ptr2=new type[n]; //ptr2ntype

delete ptr1; //ptr1

delete [ ]ptr2; //ptr2

  • ptype


3 c

  • newdelete

  • new

  • 2


3 c

  • :

    int a[10];

    int *p;

    p=&a[0];

  • a[0]ppa0C++:

    p=a;


3 c

  • :aapap

  • a[3]C++p+1p1

  • p&a[0]

  • p+ia+ia[i]ai

  • *p+i*a+ip+ia+ia[i]


3 c

  • p [i]*p+i

  • 3

  • :

  • *

  • int *p[4];

  • :


3 c

  • **

  • char **p;

  • 3.4


3 c

  • 3.5

  • C++

  • 3.5.1

  • C++

    int x;

  • for


3 c

  • {}

    {

    p_tempp0;

    p0p1;

    p1p_temp;

    }


3 c

  • 3.5.2

  • 1if

  • if

  • if

    { 1;

    n;

    }

  • if{ }


3 c

  • if3.5a

3.5 if1


3 c

  • 2if...else

  • if...else

  • if

    { 1;

    m;

    }

    else

    { m+1;

    n;

    }


3 c

  • 1mm+1nif...else{ }

  • if3.5b

  • ifififififelseif


3 c

if11;

else if22;

else if33;

else ifmm;

elsen

  • if3.6


3 c

3.6 if2


3 c

  • 3?

  • C++?

    ?1:2

  • 012

    maxa>b?a:b;

  • ifa>b


3 c

maxa;

else

maxb;

  • 4switch

  • switch

    switch

    case1


3 c

break

case2

break

Default

  • 3.5.3

  • 1for

  • for

  • for123


3 c

  • 123

  • forfor122for322for1


3 c

  • C++1

    forint i1;i<=10;i++

  • for123

  • 2forfor

  • for3.7


3 c

3.7 for


3 c

  • 2while

  • while

    while

  • while

  • for

  • for123

  • while


3 c

1

while2

3

  • while3.8a

  • 3do...while

  • do...while

    do

    while


3 c

  • do...whilewhiledo...whilewhile

  • do...while3.8b


3 c

3.8 whiledo...while


3 c

  • 3.5.4

  • 1break

  • breakswitchbreakbreak

  • 2continue


3 c

  • continuebreakcontinuecontinue

  • 3goto

  • gotogotogoto

    goto

  • goto


3 c

  • gotogoto

  • 3.6

  • 1

  • returnvoid


3 c

  • 12...

    int sumint x,int y,int z

    {

    returnx+y+z;

    }

  • C++3


3 c

inputint i //

inputfloat f //

inputchar ch //

  • 2


3 c

averagesuma,b,c/3

  • 3

  • #include


3 c

  • 8

    #include <iostream.h>

    int w=3;

    int funint;

    void main

    {

    int w=10;

    cout<<fun5*w<<endl;

    }


3 c

int funint k

{

ifk==0 return w;

return funk-1*k;

}

  • 3

  • C++


3 c

  • 4

  • main 3argcargvenvargcargvenv

  • 3.7

  • 3.7.1


3 c

  • C++

  • Class

    {

    public

    protected

    private

    }


3 c

  • class

  • C+ +3public,protectedprivate

  • Public


3 c

  • Private

  • Protected

  • :


3 c

  • 3.7.2

  • . .

  • .


3 c

  • 3.7.5

  • 1

  • return

  • PublicProtectedPrivate


3 c

  • 2

  • locationlocation location

  • class

    //

    //


3 c

//

//


3 c

  • PublicProtectedPrivate

  • 3.7.6

  • 1


3 c

  • //

    //

    class

    {


3 c

friend;

};

  • 2

  • ABABB

  • AB


3 c

class A

{

};

class B

{

friend class A;

};


3 c

  • 3.8

  • 3.8.1


3 c

  • C++

  • 3.8.2

  • class

    private


3 c

public

  • 3.8.3

  • class1...n

    {

    }


3 c

  • 3.9


3 c

  • C++

  • virtual


3 c

virtual

  • 3.10

  • 3.10.1

  • C++C++


3 c

overloaded


3 c

  • C++


3 c

  • 3.10.2

  • C++C++:+


3 c

  • operator

  • operatorvoid

  • C++33

  • C++5

  • ?:


3 c

  • .

  • ->

  • ::

  • Sizeof

  • 3.11 C++

  • C++C++FORTRANCOBOL


3 c

  • C++

  • C++cincoutcincoutiostream.h

  • C++/**///

  • C++


  • Login