Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Look for some examples of C++ programming
Look for some examples of C++ programming
One: Multiple choice questions

1. The following functions are: ()

int fun(char *x)

{

char * y = x;

while(* y++){ };

Returns y-x-1;

}

A. Find the length of the rope

B. Find the storage location of the string

C. compare the sizes of two strings.

D. concatenate the string x after the string y.

2. If there are the following descriptions and statements, and 0

int a[ ]={ 1,2,3,4,5,6,7,8,9,0},*p,I;

p = a;

a.*(a+i)

B. One

c.p+i

d.*(& amp; a[i])

3. The output of the following program is: ()

# include & ltstdio.h & gt

void main()

{

int a[ 10]={ 1,2,3,4,5,6,7,8,9, 10},* p = a;

printf(" % d " ,*(p+2));

}

a.3

B.iv.

c. 1

d.2

4. If there are the following definitions and statements, and 0

int a[ ]={ 1,2,3,4,5,6,7,8,9,0},*p,I;

p = a;

a.& amp(a+ 1)

b.a++

c.*p

d.& ampp[i]

5. It is known that: int a, x =1; The following correct assignment statement is: ()

a.a =(a[ 1]+a[2])/2;

b.a =(a[ 1]+a[2])/2;

c.a = x+2;

D.a= "good";

6. It is known that: int a[]={ 1, 2, 3, 4, 5, 6}, * p = a;; In the following expression, the value of 5 is: ()

a . p+= 3; *(p++);

b . p+= 5; * p++;

c . p+= 4; * ++ p;

d . p+= 4; ++ * p;

7. If there are the following statements and 0

int x[]={ 1,9, 10,7,32,4},*ptr=x,k = 1;

a.x++

B. & photoelectric tape reader

c.& ampptr[k]

d.& amp(x+ 1)

8. If: int i, j=7, * p; is specified; P = & Then the statement equivalent to i=j is ()

a . I = * p;

b.* p = * &j;

c.i = & ampj

d . I = * * p;

9. If p 1 and p2 are pointer variables pointing to the same one-dimensional array of type int, and k is an int variable, the statement that cannot be executed correctly is ().

a . k = * p 1+* p2;

b . p2 = k;

c . p 1 = p2;

d . k = * p 1 *(* p2);

10. If the following function definition is set, the value returned by this function is ().

int * fun(int a)

{

int *t,n;

n = a; t = & ampn;

return t;

}

A. Unavailable storage unit address values

B. Available memory cell address values

The value expressed in c.n.

D. the value in formal parameter a

Two: fill in the blanks

1, give the output result of the following program.

# include & ltstdio.h & gt

void main()

{

int *v,b;

v = & ampb; b = 100; * v+ = b;

printf("%d\n ",b);

}

2. Description statement "int(* p)(); ();" means

3. Known function statement: void * fun (); So what it means is

4, known: int I;; char * s = " a \ 045+045 \ ' b "; Execute the statement "fot(I = 0;; * s++; i++); After that, the result of variable I is

5. The following process is to find the sum of two integers and return the result through formal parameters.

int add(intx,int y,z)

{ = x+y; }

6. The output of the following program is as follows

Invalid funds (int *x)

{ printf(" % d \ n " ,++ * x)'; }

Master ()

{

int a = 25

Fun (& AMPA);

}

7. Give the running results of the following programs.

# include & ltstdio.h & gt

void main()

{

int a[ ]={ 1,2,3,4,5 };

int x,y,* p;

p = & ampa[0];

x = *(p+2);

y = *(p+4);

printf("*p=%d,x=%d,y=%d\n ",*p,x,y);

Return;

}

8. Give the running results of the following programs.

# include & ltiostream.h & gt

void callbyval(int a,int b,int c)

{

a = 3; b = 2; c = 1;

}

void callbypointer(int* a,int* b,int* c)

{

* a = 3; * b = 2; * c = 1;

}

void call by reference(int & amp; I int& international bank. c)

{

a = 1; b = 2; c = 3;

}

void main()

{

int a= 1,b=2,c = 3;

int & ampa 1 = a;

int & ampb 1 = a;

int & ampc 1 = a;

callbyval(a,b,c);

cout & lt& lta & lt& ltb & lt& ltc & lt& ltendl

callby pointer(& amp; First, & ampb & amp;; c);

cout & lt& lta & lt& ltb & lt& ltc & lt& ltendl

callbyreference(a 1,b 1,c 1);

cout & lt& lta & lt& ltb & lt& ltc & lt& ltendl

}

9. Give the running results of the following programs.

# include & ltiostream.h & gt

void ast(int x,int y,int *cp,int *dp)

{

* CP = x * y;

* DP = x % y;

}

void main()

{

int a,b,c,d;

a = 2; b = 3;

Ast(a, B and ampc, & AMPD);

cout & lt& ltc & lt& ltd & lt& ltendl

}

10, giving the results of the following program.

# include & ltstdio.h & gt

void main()

{

int a= 10,b=0,*pa,* pb

pa = & ampa; pb = & ampb;

printf("%d,%d\n ",a,b);

printf("%d,%d\n ",*pa,* Pb);

a = 20b = 30

* pa = a++; * Pb = b++;

printf("%d,%d\n ",a,b);

printf("%d,%d\n ",*pa,* Pb);

(* pa)++;

(* Pb)++;

printf("%d,%d\n ",a,b);

printf("%d,%d\n ",*pa,* Pb);

}

Three: Short answer questions and programming questions

1. After executing the following statement, determine the value of ab.

int *var,ab;

ab = 100;

var = & ampab;

ab = * var+ 10;

2. What is the value of the expression *-p when the pointer p points as shown in the figure below? (Here, one [0], one [1], one [2] ... are only used as code names of continuous storage units, with low-order address [0] and high-order address [1]).

3. there is a definition: double var, so,

A) What is the definition statement that makes the pointer p point to a variable of type double?

B) What is the assignment statement that makes the pointer p point to the variable var?

C) What is the scanf function call statement that reads data into the variable var through the pointer p?

4. Write a function, find the length of a string, input the string in the main function, and output its length.

5. Programming: Input any character string from the keyboard, and then input the character to be searched. If it exists, it returns the position where it first appears in the string; Otherwise, the output is "not found in the string!" . To realize the same character string, you can input the characters you want to find continuously.

6. Programming: Delete substring from string. Enter a string from the keyboard, and then enter the substring to delete. Finally, the new string after substring is deleted is output.

One: multiple choice questions:

1.A

2.C

3.A

4.D

5.C

6.A

7.C

8.B

9.B

10.A

Two: fill in the blanks

1.200

2.p is a pointer to a function whose return value is an integer.

3. The return value of the 3.fun function is a universal pointer.

4.8

Because the for statement is to find the length of the string, we can know that the result of I is 8.

5.( 1)int * (2)*z

6.26

7.*p= 1 x=3 y=5

8. 123

32 1

32 1

9.6 2

10. 10,0

10,0

2 1,3 1

2 1,3 1

22,32

22,32

Third, Q&A and programming problems.

1. This example defines two variables, the variable ab of type int and the pointer variable var point to type int; Statement var = &;; ab; The address of ab is assigned to var. In the next sentence, *var indicates the content of the unit referred to by var, that is, 100. Then, *var+ 10 is assigned to the variable ab; Then, the value of ab should be 1 10.

2. According to the priority of the operator, the expression *-p = * (-p). Therefore, firstly, the -P operation is performed, so that the pointer P moves to the low address direction by one memory cell, pointing to a[ 1]. Then use the operator "*" to get the data stored at this address, which is 20.

3.( 1) requires that p be defined as a pointer variable pointing to double type, so the definition statement is: double * P;;

(2) To make P point to the variable var, assign the address of var to the pointer P, and the assignment statement is: P = &;; var

(3) The statement of assigning the read data to the variable var with the scanf function is: scanf ("%lf ",&; var); Since the address of var has been assigned to p in (2), this statement is equivalent to scanf("%lf ",p);

4. The procedure is:

# include & ltstdio.h & gt

int length(char * a);

void main()

{

int len

char string[20];

Printf ("Please enter a string:");

scanf("%s ",str);

Len = length (str);

Printf ("string length is %d", len);

Return;

}

Int length(char* a)/* Find string length function */

{

char * p;

p = a;

int n;

n = 0;

while(*p! ='\0')

{

n++;

p++;

}

Return (n);

}

5. The procedure is:

# include & ltiostream.h & gt

Char *strchr( char *string, int letter)

{

While((* string! = letters)&&(* string))

string++;

Returns a string;

}

void main()

{

int TT = 1;

while(tt){

char title[64];

Cout & lt& lt Please enter a string: ";

CIN & gt; & gt title;

char * p;

Cout & lt& lt Please enter the character you are looking for:;

char ch

CIN & gt; & gtch;

p=strchr(title,ch);

If (*p)

The first occurrence of the search character in the cout & lt& lt "string is:"

other

Cout & lt& lt "There are no searched characters in the string!" & lt& ltendl

Cout & lt& lt "Be your coward! 1-count, 0-exit "< < endl

CIN & gt; & gtTT;

}

}

6. The procedure is:

# include & ltstring.h & gt

# include & ltiostream.h & gt

char* strstr_rep(char *source,char *old)

{

int i,j,k,loc =- 1;

for(I = 0; Source [I]&; & amp(loc = =- 1); i++)

for(j=i,k = 0; source[j]= = old[k]; j++,k++)

If (! Old [k+ 1])

loc = I;

If (loc! =- 1)

{

for(k = 0; Old [k]; k++);

for(j=loc,I = loc+k; Source [I]; j++,i++)

source[j]= source[I];

source[I]= NULL;

}

Return (source);

}

void main()

{

char a[50];

Cout & lt& lt Please enter a string: ";

CIN & gt; & gta;

char b[30];

Cout & lt& lt Please enter the substring of the above string: ";

CIN & gt; & gtb;

cout & lt& ltstrstr_rep(a,b)& lt; & ltendl

}