[Reprinted] the difference between referencing & amp; in C ++ and obtaining address & amp; is reprinted.

Source: Internet
Author: User

[Reprint] the difference between referencing in C ++ and getting an address.

One is used to pass the value, and the other is used to obtain the first address.

& (Reference) ==> when the variable declaration statement is on the left of the variable, it indicates that the reference is declared.

For example: int & rf; // declare an int type reference rf.
& (Obtain the address operator) ==> when an initial value is assigned to a variable, it appears on the right of the equal sign or as a unary operator in the execution statement.
The address of the object.

 

In C ++, there are both references and fetch addresses. Many people are not very clear about the references and fetch addresses, so they cannot distinguish between them. In fact, their differences can be summarized in one sentence: the type is referenced together, and the variable is accessed together. Next, let's take a look at the examples

1) The reference is on the left of the value =, and the address is on the right of the value, for example

2) references are associated with types, and addresses are associated with variables. The example is also as follows:

3) For vector, the above two entries are equally suitable.


C # c language program to c #: Value of calling another function in void

C To C # is still very simple. According to your question on the first floor, the two questions are as follows:
1. Warning: inaccessible code Detected

For (int j = 0; j <10; j ++)
{
...; // A bunch of computing code
Return c; // at this point, the compiler knows clearly that the j ++ code is returned if it is not executed. Therefore, it warns you, but it is only a warning, not an error!
}
PS: Your for statement is equivalent:
Int j = 0;
If (j <10)
{
...;
Return c;
J ++ // The compilation result shows that the statement will not be executed, so warn you
}

2. C # syntax rules. If a function specifies the return type, it must be returned at the end of the function!
Double f (double a, double B)
{
Int j = 0;
If (j <10)
{
//...;
Return c;
J ++; // The compilation result shows that the statement will not be executed, so warn you
}
// Return ???; // There must be a return statement here, because the compiler only looks at the syntax rules and does not know that j <10 Code will not run here, but if j> = 10, the above if () the {} statement block will not be executed, and the code may end and exit here, so a value is returned...
}

You are welcome to ask, it is best to post detailed code for your reference.
 
How to Use header files in C Language

Hello, in the program file C, cpp, or h header file # include "header file path + file name. h.
You can use relative paths and absolute paths. Generally, relative paths are used. When the header file is in the current project directory, you can directly write # include "header file name. h"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.