C can still run without static

Updated on technology 2024-04-13
28 answers
  1. Anonymous users2024-02-07

    class program

    int i = 20;

    int j = 30;

    static void main(string args)a();public static void a()program k = new program();

    i" +

    The value of j" +

    static is a static method that doesn't matter, you can call it directly a() if you don't go, you need to instantiate it and use it later.

    The first main method is the main function method of the console, which cannot be removed like the pageload event in the web.

    As for the reason why you can't get out of 30 is because your main function doesn't call which of the following main methods, the following methods won't be executed by themselves, and you need to call them in the main function.

  2. Anonymous users2024-02-06

    1.Remove using ;

    2.change"i" +

    Error, delete. Program doesn't have a j

  3. Anonymous users2024-02-05

    program().i);

    This output is 20

    This can output up to 30 of what you want

  4. Anonymous users2024-02-04

    c There can only be one entry point in the program, and the program will automatically generate a main method for each new project.

    The main method is declared in a class or structure. It must be a static method, and it should not be a public method.

  5. Anonymous users2024-02-03

    I've uploaded it here, you see.

    This is a brief introduction to the three uses of static:1Before using a variable, it means that every time you reuse the method, class, or custom class where the variable is located, the value of the variable is the value when the program assigns a value to the variable for the last time it runs, and this method is called a static function

    The private void s() method has a value of 2 in memory after the first group of clever calls; After the first call of the method, a has an in-memory value of 3; 2.A static method is preceded by a static method to indicate that the method is owned by the class or custom class it is in, not by an instance of the class, and this method is called a static method: Case 1:

    Non-static method: class tvoid s(...)When you call method s in this class in another method trapped chain, you need to declare the variables of this class first, such as:

    t sd = new t(..Then call the square ruler key method in t: case 2:

    Static method: class tstatic void s(..When you call method s in this class in another method, you don't need to declare the variables of this class first, such as calling method directly:

    To put it simply, all methods of this type are static methods, and the non-static methods in this class cannot be used, this type is called static class: static class t class d}

  6. Anonymous users2024-02-02

    There are 2 static variables that are defined, but they are not used in the program, so you can delete them without affecting the compilation.

  7. Anonymous users2024-02-01

    Yes, as shown in the figure below, when instantiating the mainwindow, the static variable definition statement will be run first.

    When in doubt, keep asking.

  8. Anonymous users2024-01-31

    Initialized before the static constructor initialized. If there is no static constructor, initialize when used. This is only an approximation, see for yourself, references.

  9. Anonymous users2024-01-30

    Delayed initialization, initializing static variables the first time the class is used.

  10. Anonymous users2024-01-29

    Static variables are initialized as they are used.

  11. Anonymous users2024-01-28

    You can have it initialize on startup.

  12. Anonymous users2024-01-27

    Yes, but you have to write the constructor.

  13. Anonymous users2024-01-26

    You initialize the assignment in the window load event.

  14. Anonymous users2024-01-25

    Data Members:

    There are two types of data members: static variables and instance variables.

    Static Member: Static member variables are associated with a class and can be used as a class"altogether"Some variables (which are a manifestation of commonality) do not depend on the existence of a specific object, and are accessed by adding a dot operator to the class name and the variable name.

    Function Members: Methods can be mainly divided into static methods and instance methods.

    Static method: A static method is a method that does not belong to a specific object, a static method can access a static member variable, a static method cannot directly access an instance variable, and the instance variable can be passed as a parameter to the static method when the instance function is called. Static methods also can't call instance methods directly, but indirectly, by first creating an instance of the class and then calling the static method through that particular object.

    Instance Method: The execution of an instance method is associated with a specific object, and its execution requires the existence of an object. Instance methods can directly access static variables and instance variables, and instance methods can directly access instance methods and static methods, and static methods can be accessed by adding a dot operator to the class name plus a variable name.

    When multiple instance objects exist, there is no copy of a particular instance method in memory, but rather that all objects of the same class share a copy of each instance method (the instance method only occupies a "set" of space).

    Examples: Static and non-static members in a class (version C).

    Let me write an example to demonstrate the difference between static and non-static members.

    The members of a class are either static or dynamic, and if a member of the class is declared static, then that member is static.

    A static member of a class belongs to the class, and it can be accessed without having to generate an instance of the class, that is, it can be accessed with only the class name.

    A static member is shared by all instances of a class, and no matter how many instances the class creates, a static member occupies only one area in memory.

    A non-static member of a class is owned by an instance of the class, and each time an instance of a class is created, an area is created in memory for the non-static members.

    A static method can only access the static fields of an example, while a non-static method can access all the fields of an example.

    using system;

    class employee

    public void setname(string n) non-static method.

    class sample

    n Salary: Yuan",;}

  15. Anonymous users2024-01-24

    Because you're in the same class as the main entry point, the class where main is located must require all methods to be static.

  16. Anonymous users2024-01-23

    Static methods, only static methods, or instance methods, can be called.

    Methods in the same class should also follow this principle.

  17. Anonymous users2024-01-22

    static void main(string args)

    Only static methods can be called. Either that, or you have to use invoke

  18. Anonymous users2024-01-21

    There are three uses of static: 1Before using a variable, it means that every time you reuse the method, class, or custom class where the variable is located, the value of the variable is the value when the program assigns a value to the variable for the last time it runs, and this method is called a static function

    After the first call of the private void s() method, a has an in-memory value of 2; After the first call of the method, a has an in-memory value of 3; 2.A static method is preceded by a static method to indicate that the method is owned by the class or custom class it is in, not by an instance of the class, and this method is called a static method: Case 1:

    Non-static method: class tvoid s(...)When you call the method s in this class in another method, you need to declare the variable of this class as follows:

    t sd = new t(..Then call the method in t:; Scenario 2:

    Static method: class tstatic void s(..When you call method s in this class in another method, you don't need to declare the variables of this class first, such as calling method directly:

    3.To put it simply, all methods of this type are static methods, and the non-static methods in this class cannot be used, this type is called static class: static class t class d}

  19. Anonymous users2024-01-20

    Static modifiers of variable methods You can think of them as when a global variable or a static method of a method class doesn't belong to an instance. Belong to the whole class! That's it!

  20. Anonymous users2024-01-19

    The definition of static in c is static, for example, if a method is defined as a static modifier, it means that it is a static member, which does not change with the instance, and it is accessed by the class name, and cannot be instantiated to access a static member.

  21. Anonymous users2024-01-18

    return is no different from other returns, they are all returned to the previous caller, for example, if you enter 3, it will be return 3*fac(3-1), and this fac(3-2) will return 2, so the result is 3*2, and the input 4 is the same, and the first is 4*fac(4-1)=>4*3*fac(3-1)=>4*3*2

    You add it at the top of that fac function"n=",n);It will be clearer.

  22. Anonymous users2024-01-17

    You have to understand how the operating system calls functions, which have stack-like data structures. Constant pressing. If you type 1, you'll see stackoverflowexception.

  23. Anonymous users2024-01-16

    public static dataset dataset = new dataset();

    This is a static variable.,It will be called into memory when the program starts.,Just use it directly later.,No need to initialize it again.,Twice it should be that you initialize it again.。

    Static is for the purpose of improving efficiency, sacrificing the resources of the system, and it must be correctly understood before it can be used, not used indiscriminately.

  24. Anonymous users2024-01-15

    The information is insufficient, and it is not easy to analyze, but it is estimated that it should be because your dataset is static, and in the program running, after being filled once, it is not released, and then it is filled for the second time.

    It is recommended that you add a breakpoint to the kclackgoods method to know how many times it has been called.

  25. Anonymous users2024-01-14

    Then you can remove static and try it, why static.

  26. Anonymous users2024-01-13

    1. The entry function of the C program is static void main(string args), so this must be added.

    2. Only static methods can be called in static functions.

    3. If you want to call a non-static method, it is as follows (remove the static before the swapifgreater method):

    static void main(string args)

  27. Anonymous users2024-01-12

    static is a static method that can be accessed directly through the class name without the need to instantiate an object of that class.

  28. Anonymous users2024-01-11

    If you don't add static, you have to call it with a new object, and here you need a new program object to call it.

Related questions
21 answers2024-04-13

Of course, eggplant can be eaten without peeling, eggplant skin contains rich nutrients vitamin C and B vitamins, after eating it has a good maintenance effect on physical health, it can play a good role in improving human physical fitness after eating in ordinary life, and you can often eat some eggplant in ordinary life to help maintain physical health, but although eggplant skin contains rich nutrients in ordinary life, it is still necessary to clean it when eating, Because some pesticide residues will occur more or less in the process of planting, it is better to clean the eggplant skin before eating it in ordinary life. >>>More

9 answers2024-04-13

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

6 answers2024-04-13

Understand the following rules: 1) Overloading an operator does not change the priority of the operator. >>>More

11 answers2024-04-13

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More

6 answers2024-04-13

This thing is basically useless.

va_list arguments; >>>More