1. How to understand the videolinesize? ?

2. What type of long is in C language? What is a floating point?

  • Long is an integer, yeslong intThe abbreviation of
  • Floating point withFloat, double,said

C++ value passing, pointer passing, reference passing

1. Briefly describe what value passing is.

  • Parameters are copies of arguments, and changing the value of a parameter does not affect the value of the external argument.
  • From the point of view of the called function, value passing is one-way (argument -> parameter), the value of the parameter can only be passed in, not out.

2. What is pointer passing?

  • A parameter is a pointer to the address of the argument. A pointer to a parameter is an operation on the argument itself.

3. Briefly describe what passing by reference is.

  • A parameter is equivalent to an argumentThe aliasOperations on parameters are operations on arguments.

4. If yesValue passing, pointer passing, reference passingWhen the concept is vague, suggest to practice the following code?

#include <iostream>

using namespace std;

/ / value
void change1(int n) {
 cout << "Value passing -- function operation address:" << &n << endl;
 n++;
}

// Reference passing
void change2(int &n) {
 cout << "Reference passing -- function operation address:" << &n << endl;
 n++;
}

// Pointer passing
void change3(int *n) {
 cout << "Pointer passing -- function operating address:" << n << endl;
 *n = (*n + 1);
}

int n = 10;
int main(a){
 
 cout << "Address of argument" << &n << endl;
 change1(n);
 cout<<"after change1() n="<<n<<endl;
 change2(n);
 cout<<"after change2() n="<<n<<endl;
 change3(&n);
 cout<<"after change3() n="<<n<<endl;
 
 int *p = &n;
 cout << "p:" << p << endl;
 
 change3(p);
 cout<<"after change3() n="<<n<<endl;
 
 return 0;
}

Copy the code

What is the difference between arrays and Pointers in terms of access?

1. What’s a Declaration? What’s a Definition? What is a declaration in C? What is the definition?

  • Statement Declaration:Describes objects that are created elsewhere and do not allocate memory. (Can appear in multiple places)
  • Define the Definition:Create a new object and allocate memory. (Can only appear once)

2. Notice the difference between “address Y” and “contents of address Y”?

“Address y” represents the memory address of variable y, and “the contents of address Y” refers to the contents located at that address, which is the value of variable Y. Most programming languages use the same symbol for both things, and the compiler decides what it means based on the context. The following figure

  • X refers to the address represented by x, while Y refers to the content of Y.
  • The value that appears to the left of the assignment symbol is called an lvalue, and the value to the right of the assignment symbol is called an rvalue. The compiler assigns an address (an lvalue) to each variable. This address is known and always exists at compile time, and its rvalue is known at run time. In layman’s terms, each variable has an address that is known at compile time, but what is stored there (the value of the variable) is known only at run time. If the value of a variable is needed (that is, the value stored at a known address), the compiler issues instructions to read the value from the specified address and place it in the corresponding register.

3. Use directlyAn array nameThe process of accessing an array element

  • A = 9980 ② (9980+ I

Use 4.Pointer to an arrayThe process of accessing an array element

  • ① The address of pointer P is 4624 ② The address 5081 stored in address 4624 ③ (5081+ I

5. To summarizeAn array namePointer to an arrayWhat’s the difference between accessing an array element?

  • In the case of array A [], the element in the array can be accessed by its name, because its contents are the first element and its next address corresponds to the address of the next element.
  • If it is a pointer *a, we fetch the contents of a, and then take it as the address of the variable and get the contents of the variable from that address.

5. Are C array parameters Pointers? Why is that? (Very important)

  • C will treat an array parameter asPointer to the
  • Thinking of the array as a parameter as a pointer is a matter of efficiency. C language summary, all non-array data arguments areValue transfer form.
  • For arrays, if you copy the entire array every time you call a function, it will cost a lot of performance and space overhead. Therefore, for arrays, the mechanism of C language is to tell the function the first address of the array, and directly operate on the array.