The difference between out and ref in C

Updated on technology 2024-02-28
9 answers
  1. Anonymous users2024-02-06

    rel is in and out, out is only in and out.

  2. Anonymous users2024-02-05

    1.The ref keyword makes the arguments pass by reference. The effect is that when control is passed to a method, any changes made to the parameter in the method will be reflected in that variable.

    To use the ref parameter, both the method definition and the method call must explicitly use the ref keyword.

    2.The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that the ref requires that the variable must be initialized before it can be passed.

    To use the out parameter, both the method definition and the method call must explicitly use the out keyword.

    Different: With ref, the variable must be initialized before being passed, not necessarily inside the function. out must be initialized inside the function.

    For example, one method uses ref.

    public static void testref(ref int num1)

    When using this method (the correct use of annoying).

    static void main(string args), num1);The value is 100

    The use of error ref is.

    static void main(string args), num1);}

  3. Anonymous users2024-02-04

    1. Both are passed by address, and the value of the original parameter will be changed after use.

    2. ref can pass the value of the parameter into the function, but out is to clear the parameter, that is, you can't pass a value from out in, after out, the value of the parameter is empty, so you have to initialize it once.

    This is the difference between the two, or as some netizens said, ref is in and out, and out is only in and out.

    3. When using ref parameters, the input parameters must be initialized first. out, which must be initialized in the method.

    4. When using ref and out, add ref or out keywords to the parameters of the method and the execution method. to meet the match.

    5. out is suitable for use where multiple return values of retrun are needed, while ref is used when the method that needs to be called modifies the caller's reference.

  4. Anonymous users2024-02-03

    ref needs to be defined in the function out, and the parameter definition out must be initialized.

  5. Anonymous users2024-02-02

    ref is a value reference. Wherever the variable is referenced, the changes are made that modify the original value.

    For example, inta=0;

    b=refa;c=ref

    b;Any change to c, a will change because they refer to a's pointer out type is an output parameter, and normal arguments cannot be output.

    params

    I'm guessing it's an indefinite number of parameters.

  6. Anonymous users2024-02-01

    , out type parameters:

    The ref usage is equivalent to a reference type parameter, which can pass the parameter of the value type into the function by means of address reference, and the value of the value type argument outside the function will be changed after the operation in the function. The main difference between ref and out is that a non-out parameter must be assigned before it can be used, while an out parameter must be assigned before the end of the method.

    Usage of type parameters.

    The params type here is actually just an array of parameters, which is sorted according to a certain collation specified in the method, and then the corresponding items of the corresponding parameter array in the method determine how to execute, and its main function is not to limit the number of parameters of the method.

  7. Anonymous users2024-01-31

    Hello:Commonality:

    Both ref and out pass arguments by reference.

    To use the ref and out parameters, both the method definition and the method call must explicitly use the ref and out keywords.

    Difference: Parameters modified with ref must be initialized first, while parameters with out are not.

    Note: The ref and out keywords are handled differently at runtime, but are handled the same at compile time. Therefore, if one method takes the ref parameter and the other method takes the out parameter, you can't overload both methods.

    If one method takes either the ref or out argument and the other doesn't, you can overload it.

  8. Anonymous users2024-01-30

    Regardless of whether out or ref is used as a parameter of a method, the change value of this parameter can be obtained after the method is executed.

    The difference in my opinion is.

    The ref needs to be declared and assigned outside of the method, i.e. before passing the argument.

    out, on the other hand, needs to be declared and assigned within the method.

  9. Anonymous users2024-01-29

    out means that this parameter is initialized and assigned inside the method after being passed into that method, and you only need to declare it when calling this method.

    The ref indicates that this parameter must be initialized or assigned before it can be called, and then after it is passed to the method, any changes to this variable inside the method will be retained.

Related questions
8 answers2024-02-28

Vitamin C is a water-soluble vitamin; Vitamin E is a fat-soluble vitamin! The other difference is that they do different things!

7 answers2024-02-28

The difference is that there are two differences.

10 answers2024-02-28

The difference is: the meaning of the expression is different. >>>More

4 answers2024-02-28

Indexer definitions are similar to properties but their functionality is not the same as properties Indexers provide a special way to write get and set accessors Properties can access an object's data in the same way as a field Indexers allow users to access class members in the same way as arrays The syntax for defining an indexer is as follows: >>>More

19 answers2024-02-28

The land temple is also known as the Fude Temple, Bogong Temple, which is generally a small building built spontaneously in the folk village, with simple shape, very small scale, and often extremely simple. The nature enshrined in the land temple is the land lord, also known as the god of good fortune. In fact, the land lord is the personification of the ancient Chinese land worship. >>>More