This presentation is the property of its rightful owner.
Sponsored Links
1 / 109

第八章 PowerPoint PPT Presentation


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

第八章. 指针. 例如:. printf( ″ %d ″ ,i) ;. scanf( ″ %d ″ ,&i);. k=i+j;. §8.1 地址和指针的概念. 为了说清楚什么是指针,必须弄清楚数据在内存中是如何存储的,又是如何读取的。. 内存区的每一个字节有一个编号,这就是“ 地址 ” 。如果在程序中定义了一个变量,在对程序进行编译时,系统就会给这个变量分配内存单元。. 1、按变量地址存取变量值的方式称为“ 直接访问 ”方式. 另一种存取变量值的方式称为“ 间接访问 ”的方式。即,将变量i的地址存放在另一个变量中。.

Download Presentation

第八章

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


6472844


6472844

;

8.1


6472844

i_pointer(3010)(3011)i_pointer

(2000)i_pointeri_pointer(2000) i_pointer(2000)2000 200


6472844

2000i_pointer


6472844

8.2

8..1

*


6472844

float *pointer_ // pointer_float

char *pointer_ //pointer_

pointer_

pointer_


6472844

  • *

  • : float *pointer_1

  • pointer_1* pointer_1

  • (2)

  • float a;

  • int * pointer_1;

  • pointer_1=&a; /* float */


6472844

8..

#include <stdio.h>

voidmain ( )

int

int*pointer_ *pointer_

pointer_ pointer_

printf%%\,,

printf%%\,*pointer_, *pointer_


6472844

*

pointer_

(1)*pointer_**pointer_*pointer_apointer_2*pointer_

pointer_2pointer_2


6472844

(2) **a**pointer_*

(3)*pointer_*pointer_++**(pointer_)++pointer_1pointer_*pointer_pointer_


6472844

8 . 2

#include <stdio.h>

void main

int *1*2*

scanf

1

if

printf=,=\\,,

printfmax=,min=\,*1,*2


6472844


6472844

8..3

#include <stdio.h>

void main

void swapint *int *;

int

int *pointer_*pointer_

scanf

pointer_ pointer_2

if)swap pointer_ pointer_2

printf\\

void swapint *int *

int temp

temp*1

**

*temp


6472844

8. 3

#include <stdio.h>

void main

void exchangeint *1 int *2 int *3;

int ***

scanf%%%&, &, &

exchange

printf,,,,,


6472844

void exchangeint * int * int *

void swapint * int *;

if** swap

if** swap

if** swap

void swapint * int *

int temp

temp*

**

*temp


6472844

8.3


6472844

8.3.1

()

*

()


6472844


6472844

8..

**

10.5


6472844

(1)

#include <stdio.h>

void main

int

int

for

scanf

printf

for

printf


6472844

(2)

#include <stdio.h>

voidmain

int

int

for

scanf

printf

for

printf*


6472844

(3)

#include <stdio.h>

void main

int

int *

for

scanf

printf

for

printf *


6472844

8.

#include <stdio.h>

void main

int*

for

scanf

printf

for

printf*


6472844

1 2 3 4 5 6 7 8 9 0

22153 234 0 0 30036 25202 11631 8259 8237 28483


6472844

#include <stdio.h>

void main

int*

for

scanf

printg

p=a;

for

printf*


6472844

8..3

88.7

void main

{iint []int ;

int

void (int int )

{

}


6472844

f (int arr , int n)

arrf

f (int *arr, int n)

C


6472844

8


6472844

#include <stdio.h>

void main

void invint int ;

int

printfThe original array:

for

printf

printf

inv

printfThe array has been in verted\

for

printf

printf


6472844

void invint int /*x*/

int temp

for

temp

temp

return


6472844

The original array

The array has been inverted


6472844

inv

#include <stdio.h>

void main

void invint *int ;

int

printf The original array:

for

printf

printf

inv

printf The array has been in verted\

for

printf

printf


6472844

void invint *int /*x*/

inttemp**

for

emp****temp

return


6472844

(1)

void main void int [ int

int {

}


6472844

(2)

void void int *int

int {

}

(3)

void main void int *int

int , *p=a; {

p }


6472844

(4)

void main void int x[ ]int

,*p=a {

p }


6472844

#include <stdio.h>

void main

{ void invint *int ;

int *

printfThe original array:\n

for

scanf

printf

inv /* */

printfThe array has been inverted

for

printf*

printf


6472844

void invint *int

inttemp**

for

emp****temp

return


6472844

89

#include <stdio.h>

void main

{ void sortint int ;

int*10

for

scanf

sort

for

*


6472844

void sortint [ ]int

int

for

for


6472844

8..

1.

, :

int a34={{1357}}

a3


6472844

80

#include <stdio.h>

define FROMAT

void main

int [3][4]13579

printf*

printf[0] , *

printf[0][0][0]

printf[1]

printf[1][0]*++

printf*

printf

printf**


6472844

(000)

(00)

(0000)

(101)

(10)

(20)

(2)

(10)


6472844

2 .

(1)

8.11

1 3 5 7

9 11 13 15

19 21 23

#include <stdio.h>

void main

int [3][4]1,3,5,7,9,11,13,15,17,19,21,23

int*

for

printf

printf*


6472844

printfaddr, value2,,*

TC++


6472844

(2)

10.13

#include <stdio.h>

void main ( )

int 1357911

1315

int *

scanf

printf

**


6472844

3.

10.13


6472844

#include <sydio.h>

void main

{ void averagefloat *pint n

void searchfloat (*p4int n)

float score34={{65677060}{80

879081}{909910098}};

average*score12*12*

searchscore**


6472844

void averagefloat *int

{ float*_

float

_

_

*

printfaverageaver


6472844

void searchfloat (*)[4]int

/ * p4 */int

printfthe score of No. % are

for)

printf5.2**

....


6472844

10.4

#include <stdio.h>

void main

void searchfloat (*p)4int n/**/

float score[3][4]={{65577060}{5887

9081}{909910098}};

searchscore


6472844

void searchfloat (*p)4int

int

for)

flag

for)

if**)flag

if

{ printf("No.%d failshis scores are:n"j+1);

for

printf%.*(*()))

printf

s

. . . .

s

. . . .


6472844

10.

10

(1)

10.5

#include <stdio.h>

void main

char string

printf


6472844

(2)

106

#include <stdio.h>

void main

charstring

printf


6472844

10.7

#include <stdio.h>

void

char [ ] am a boy[20]

int

for*

**

*

printfstring a is

printf

for

printf

printf


6472844

10.8 107

#include <stdio.h>

void main

char [ ] =I am a boy. [20]*p1*p2

int

for*p1p2


6472844

**

*

printfstring is

printf

for

printf

printf


6472844

10..

1019

(1)

#include <stdio.h>

void main

{ void copy_stringchar from char to ;

char a[ ]= am a teacher

char [ ]=you are a student

printf(string a= string

)

printf("copy string a to string b:\n ");

copy_string

printf("nstring a=%snstring b=%sn"ab);


6472844

void copy_stringchar from char to

int

while

copy string a to string b:


6472844

#include <stdio.h>

void main

{ void copy_stringchar * char *;

char * am a teacher .

char *you are a student

printf("string a= )

printf("copy string a to string b:\n ");

_

printf("nstring a=%snstring b=%sn"ab);


6472844

void copy_stringchar *char *

for*fromfromto

*

*

copy_string

1copy_string

void copy_string char *char *

while**


6472844

2 copy_string

while*to*from

3copy_string

{

while*

**

*


6472844

4whilewhile

while**

while*to*from

****

5

for*to*from

for*to*from


6472844

6copy_string

void copy_string char from char

**

while*p2*p1

10..


6472844

(1) 1

(2)

char str

str

char*


6472844

(3)

char * love China

char*

char str love China;

char str

str


6472844

(4)

: char str

scanfstr

,

char*

scanf


6472844

*

(5)

10.0

#include <stdio.h>

void

char*I love China

printf


6472844

101

#include <stdio.h>

voidmain

char* love hina!

int

printf ( The sixth character is %cn"a5);

for

printf


6472844

10.

10..

10.2


6472844

#include <stdio.h>

voidmain

int maxintint

int

scanf

printf

int maxint int

int

if

else

return


6472844

main

#include <stdio.h>

voidmain

int intint

int *

int

scanf

*

printf


6472844

10..

subx1x2x1x2sub


6472844

f1

void int (*x1)(int)int (*x2)(int,int)

int

* **

***


6472844

10.3 processprocess

#include <stdio.h>

void main

int maxintint; /* */

int minintint; /* */

int addintint /* */

void process (int,int,int(*fun)(); /* */

int

printf

scanf


6472844


6472844

int int int /* */

int int int /* */


6472844

int int int /* */

void process(int int int (*fun)(int,int))

*


6472844

10.

*;

*int int ;


6472844

104

#include <stdio.h>

void main

float *score 4={{60708090}

{56896788}{34789066}};

float*searchfloat (*pointer)4int n

float*

int

printfenter the number of student

scanf

printfThe scores of No are\


6472844

search

for

printf*

float * searchfloat (*)4int

float *

*

return

enter the number of student

The scores of No. are

56.00 89.00 67.00 88.00


6472844

105

#include <stdio.h>

void main

{float score 4={{60708090}{56

896788}{34789066}};

float searchfloat (*pointer)4

float*

i


6472844

f

*

printfscores

for)

printf*

printf


6472844

10.

10..

*[]


6472844

106

#include <stdio.h>

#include <string.h>

void main

void sortchar *name int n

void printfchar *name int n

char *name ={"Follow me""BASIC""Great Wall"FORTRAN""Computer design"};

int

sort

print


6472844

void sortchar * int

char *

int

for

for

ifstrcmpname[]name[]>0=

if!

temp=namei;

namei=namek;

namek=temp;


6472844

void printchar * int

printf

}


6472844

10

**

**********


6472844

107

#include <stdio.h>

void main

char *name={"Follow me""BASIC""Great

Wall"FORTRAN""Computer design"};

char **

int

for

printf*


6472844

10.28

#include <stdio.h>

void main

int

int *num5=&a0&a1

&a2&a3&a4

int **

for

printf **


6472844

10..

mainvoid main

mainvoid mainint argcchar *argv[ ]

argcargvmainmainmainmain


6472844

:

void mainint char *

DOS


6472844

10.

10.8.1


6472844

10.8.2

(1)

(2)

array

array

max


6472844

(3)

(4)


6472844

(5)

10.8.3 void

ANSICvoidANSICvoid:

*

*

*


6472844

* *

*

*:

*char ch1char ch2

*hh


  • Login