{printf("intg=%d &intg=%p ",intg, &intg);
printf("fltp=%f &fltp=%p\n",fltp, &fltp);
intg+=10; fltp*=2;
printf("intg_n=%d fltp_n=%f\n",intg,fltp);}
Void main()
{int i=200; float f=100.25;
Func(i,f);
printf("i=%d &i=%p f=%f &f=%p\n",i,&i,f,&f);}
:
intg=200 &intg=8FD8:0FF2 fltp=100.25 &fltp=8FD8:0FF4
intg_n=210 fltp_n=200.5
i=200 &i=8FD8:0FFC f=100.25 &f=8FD8:0FF8
( ) , , , , , .
. :
#include <stdio.h>
void swap(int *a, int *b) //
{printf("&a=%p a=%p *a=%d\n",&a,a,*a);
printf("&b=%p b=%p *b=%d\n",&b,b,*b);
int tmp=*a; *a=*b; *b=tmp;
printf("*a_n=%d *b_n=%d\n",*a,*b);}
Void main()
{int i=5,j=60;
printf("&i=%p i=%d &j=%p j=%d\n",&i,i,&j,j);
swap(&i,&j); //
printf("i=%d j=%d\n",i,j);}
:
&i=8FD8:0FFE i=5 &j=8FD8:0FFC j=60
&a=8FD8:0FF4 a=8FD8:0FFE *a=5
&b=8FD8:0FF8 b=8FD8:0FFC *b=60
*a_n=60 *b_n=5
i=60 j=5
1.3
. -, . : (-
int func1(int arr[]) {...}
int func2(int *mass) {...}
, - . , arr++. (arr[1], arr[i]), (*(arr+1), *(arr+i)).
. , .. 4 .
: 1) ; 2) - , .
. , .
#include <stdio.h>
int sum(int N,int x[]) //
|
|
{int S=0;
for(int i=0;i<N;i++) S+=x[i];
return S;}
Void main()
{int a[5]={1,3,5,10,2},c[3]={2,1,6},res1,res2;
res1=sum(5,a); //
printf(" a=%d\n",res1); // 21
res2=sum(3,c); //
printf(" c=%d\n",res2);} // 9
. , '\0'.
#include <stdio.h>
int len(char *); //
Void main()
{char *name="TERMINATOR";
printf(" 1- =%d",len(name)); // 10
char *str=" ";
printf(" 2- =%d",len(str)); } // 17
int len(char *c) //
{int i=0;
while(c[i++]);
return i-1; } // ' \0 '
. , , void
#include <stdio.h>
void exch(int, int []); //
Void main()
{int a[5]={1,3,5,8,2};
printf(" : ");
for(int i=0;i<5;i++) printf(" %d",a[i]);
exch(5,a); //
printf("\n : ");
for(int i=0;i<5;i++) printf(" %d",a[i]);
}
void exch(int N,int x[]) //
{for(int i=0;i<N;i++) x[i]*=x[i];}
:
: 1 3 5 8 2.
: 1 9 25 64 4.
1.4
, . . :
_=_
: , .
. 2-
#include <stdio.h>
int def(int a=10, int b=3){return a*b;}
Void main()
{int am=2, bm=5, res1,res2,res3;
res1=def(); // 10*3=30
res2=def(am); // 2*3=6
res3=def(am,bm); // 2*5=10
printf("res1=%d res2=%d res3=%d\n",res1,res2,res3); }
:
res1=30 res2=6 res3=10
main(), , ( ) .
. 3-
#include <stdio.h>
int sum(int,int=5,int=10); //
Void main()
{int am=20, bm=50, cm=100, s1,s2,s3,s4;
s1=sum(am); // 20+5+10=35
s2=sum(am,bm); // 20+50+10=80
s3=sum(am,bm,cm); // 20+50+100=170
printf("s1=%d s2=%d s3=%d\n",s1,s2,s3);}
int sum(int a,int b,int c) //
{return a+b+c;}
:
s1=35 s2=80 s3=170
1.5
, . :
|
|