C language tutorial pointer definition and characteristics (previous post)

Definitions

Int i; Define integer variable i

Int *pp is a pointer variable to integer data

Int a[n]; defines the integer array a, which has n elements

Int *p[n]; defines the pointer array p, which consists of n pointer elements that point to integer data

Int (*p)[n]; p is a pointer variable to a one-dimensional array containing n elements

Int f(); f is a function with an integer function value

Int *p(); p is a function that returns a pointer to the integer data

Int (*p)(); p is a pointer to a function that returns an integer value

Int **p; P is a pointer variable that points to a pointer variable to integer data

//------------------------------------------------ ------------------------------------------

The formal parameters and arguments of a function have the following characteristics:

1. A parameter variable allocates a memory location only when it is called, and immediately releases the allocated memory location at the end of the call.

C language tutorial pointer definition and characteristics (previous post)

Therefore, the parameters are only valid inside the function. After the end of the function call returns the main function, the parameter can no longer be used.

2. The arguments can be constants, variables, expressions, functions, etc. No matter what type of argument the argument is, when the function is called,

Both must have certain values ​​in order to pass these values ​​to formal parameters. Therefore, assignments, inputs, etc. should be used in advance to make the actual parameters obtain a certain value.

3. The actual parameters and formal parameters should be strictly identical in number, type, and sequence; otherwise, type mismatch "errors may occur.

4. The data transfer that occurs in the function call is unidirectional. That is, the value of the actual parameter can only be passed to the parameter, and the value of the parameter cannot be transmitted to the actual parameter in reverse.

Therefore, during the function call, the value of the parameter changes and the value in the actual parameter does not change.

//------------------------------------------------ ------------------------------------------

There are several differences between using an array name as a function parameter and using an array element as an argument:

1) When using array elements as arguments, as long as the array type and the function's parameter variables are of the same type,

Then the type of the array element as a subscript variable is the same as the type of the function parameter variable.

Therefore, it is not required that the formal parameters of the function are also subscript variables. In other words, the processing of array elements is treated as ordinary variables.

When using an array name as a function argument, both the argument and the corresponding argument must be arrays of the same type, and all must have a clear array description.

When the parameters and actual parameters are inconsistent, an error will occur.

2) When an ordinary variable or subscript variable is used as a function parameter, a parameter variable and an actual parameter variable are two different memory elements allocated by the compiling system.

The value transfer that occurs when the function is called is to assign the value of the argument to the parameter variable. When using an array name as a function parameter, it is not a value transfer.

That is, the value of each element of the real parameter group is not given to each element of the parameter group. Because the actual parameter group does not exist, the compilation system does not allocate memory for the parameter group.

So how is the data transfer implemented? As we mentioned before, the array name is the first address of the array.

Therefore, the transmission of the array name as a function parameter is only the transmission of the address, that is to say, the first address of the real parameter group is assigned to the name of the parameter group.

After the parameter group name gets this first address, it also means that there is a real array. In fact, the parameter group and the real parameter group are in the same array and share a memory space.

************************************************** *****************************************/

#i nclude

#i nclude

#i nclude

#i nclude

#i nclude

Bit bflag;

Void ser_init(void)

{

SCON = 0x50; //Serial port mode 1, allowing reception

TMOD = 0x20; // Timer 1 timing mode 2

TCON = 0x40; //Set timer 1 to start counting

TH1 = 0xE8; //11.0592MHz 1200 baud rate

TL1 = 0xE8;

TI = 1;

TR1 = 1; // start the timer

}

#if 0

/ / Example 10.2 output size by changing the value of the pointer variable (pointer)

Void main(void)

{

While(1)

{

If(!bflag)

{

Int *p1,*p2,*p,a,b;

Ser_init();

Printf("input two numbers:n");

Scanf("%d,%d",&a,&b);

P1=&a;

P2=&b;

If(a {

p=p1;

P1=p2;

P2=p;

}

Printf("a=%d,b=%dn",a,b);

Printf("max=%d,min=%dn",*p1,*p2);

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ --------------------------------------------

#if 1

/ / Example 10.5 custom function pointer for function parameter transfer

/ / Actual parameters and parameters refer to the variables a and b. It is not possible to change the actual parameters by changing the value of the parameter.

// Only change the parameter to the value of the variable to make the actual parameter data change

Void swap(int *p1,int *p2)

{

Int temp;

Temp = *p1;

*p1 = *p2;

*p2 = temp;

}

Void exchange(int *q1,int *q2,int *q3)

{

If(*q1 *q2) swap(q1,q2);

If(*q1 *q3) swap(q1,q3);

If(*q2 *q3) swap(q2,q3);

}

Void main(void)

{

While(1)

{

If(!bflag)

{

Int a,b,c;

Int *pointer_1,*pointer_2,*pointer_3;

Ser_init();

Printf("input three numbers:n");

Scanf(”%d%d%d”,&a,&b,&c);

Pointer_1 = &a;

Pointer_2 = &b;

Pointer_3 = &c;

Exchange(pointer_1,pointer_2,pointer_3);

Printf("%d,%d,%dn",a,b,c);

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ ------------------------------------

//The value of the argument did not switch, only the value of the parameter exchanged

#if 0

Void swap(x,y)

{

Int temp;

Temp = x;

x = y;

y = temp;

}

Void main(void)

{

While(1)

{

If(!bflag)

{

Int a,b;

Ser_init();

Printf("input two numbers:n");

Scanf(”%d%d”,&a,&b);

Swap(a,b);

Printf("%d,%dn",a,b);

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ -----------------------------------

//Subscript access array elements

#if 0

Void main(void)

{

Int a[10],i;

Ser_init();

For(i=0;i"10;i++)

{

a[i]=i;

}

For(i=0;i"10;i++)

{

Printf("a[%d]=%dn",i,a[i]);

}

}

#endif

#if 0

// The pointer method indirectly accesses the array element and evaluates the element address through the array element to find the value of the element

Void main(void)

{

Int a[10],i,*p;

Ser_init();

p=a;

For(i=0;i"10;i++)

{

// a[i]=i;

*(a+i)=i;

}

For(i=0;i"10;i++)

{

Printf("a[%d]=%dn",i,*(a+i));

}

}

#endif

//------------------------------------------------ ------------------------------------------

/ / Example 10.15 pointer to the argument passed to the pointer parameter

#if 0

Float aver(float *pa)

{

Int i;

Float av=0,sum=0;

For(i=0;i<5;i++) sum=sum + *pa++;

Av=sum/5;

Return av;

}

Void main(void)

{

While(1)

{

If(!bflag)

{

Int j;

Float sco[5],av,*sp;

Sp=sco;

Ser_init();

Printf("input five scores:n");

For(j=0;j<5;j++) scanf(”%f”,&sco[j]);

Av=aver(sp);

Printf("%5.2fn",av);

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ ---------------------------------------

//selection sorts 10 integers

//Thinking: For example, an array sequence 10 45 8 55 45 41 23 17 85 63

// Compare 10 to the next 9 numbers. If it's bigger than 9, swap it. If 45 is greater than 10, then subscript 0 of subscript 1 of 45 is stored in 10, and so on.

#if 0

Void SelectSort(int x[],int n)

{

Int i,j,k,t;

For(i=0;i {

k=i; //The index of a number in the outer loop temporarily exists in the variable k

For(j=i+1;j {

If(x[j]"x[k]) k=j;

}

If(k!=i) // The inner loop loops once, swapping the value of the array element if there is a larger number than the outer loop.

{

t=x[i]; //t is an intermediate variable

x[i]=x[k];

x[k]=t;

}

}

}

#endif

//Bubbling sorting principle, heavy under, light above

#if 0

Void BubbleSort(int x[],int n)

{

Int i,j,temp;

Bit bexchange; //x0 x1 x2 x3. .x(n-1)

For(i=1;i {

Bexchange=0;

For(j=n-1;j=i;j--)

{

If(x[j+1] x[j])

{

Temp = x[j+1];

x[j+1] = x[j];

x[j] = temp;

Bexchange = 1;

}

// if(!bexchange) return;

}

}

}

Void main(void)

{

While(1)

{

If(!bflag)

{

Int *p,i,a[10]={3,7,9,11,0,6,22,5,4,2};

Ser_init();

Printf("The original array:n");

For(i=0;i"10;i++) printf("%d,",a[i]);

Printf("n");

p=a;

// SelectSort(p,10);

BubbleSort(p,10);

For(i=0;i"10;i++)

{

Printf("%d",*p);

p++;

}

Printf("n");

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ ----------------------------------

// pointer variable to a two-dimensional array

#if 0

Void main(void)

{

While(1)

{

If(!bflag)

{

Int a[3][4]={

0,1,2,3,

4,5,6,7,

8,9,10,11

};

Int i,j;

Int (*p)[4]; //defines a pointer to a two-dimensional array pointer

Ser_init();

p = a; // The first row address of array a is assigned to a two-dimensional array pointer variable p

For(i=0;i"3;i++)

{

For(j=0;j<<4;j++)

{

Printf("%d",*(*(p+i)+j) );

}

Printf("n");

}

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ -------------------------------------

// character pointer variable

#if 0

Void main(void)

{

While(1)

{

If(!bflag)

{

Char *ps=”I Love China!”;

Int n=10;

Ser_init();

Printf("%s",ps);

Bflag = 1;

}

}

}

#endif

//------------------------------------------------ --------------------------------------------

ZGAR AZ CC Vape

ZGAR AZ CC Disposable


ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.


Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.


We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.



ZGAR AZ CC Vape,ZGAR AZ CC Vape disposable electronic cigarette,ZGAR AZ CC Vape vape pen atomizer , AZ CC E-cig,AZ CC disposable electronic cigarette

Zgar International (M) SDN BHD , https://www.sze-cigarette.com