Runtime vs. Compile time

前端 未结 27 925
后悔当初
后悔当初 2020-11-22 06:50

What is the difference between run-time and compile-time?

相关标签:
27条回答
  • 2020-11-22 07:26

    I think of it in terms of errors, and when they can be caught.

    Compile time:

    string my_value = Console.ReadLine();
    int i = my_value;
    

    A string value can't be assigned a variable of type int, so the compiler knows for sure at compile time that this code has a problem

    Run time:

    string my_value = Console.ReadLine();
    int i = int.Parse(my_value);
    

    Here the outcome depends on what string was returned by ReadLine(). Some values can be parsed to an int, others can't. This can only be determined at run time

    0 讨论(0)
  • 2020-11-22 07:26

    (edit: the following applies to C# and similar, strongly-typed programming languages. I'm not sure if this helps you).

    For example, the following error will be detected by the compiler (at compile time) before you run a program and will result in a compilation error:

    int i = "string"; --> error at compile-time
    

    On the other hand, an error like the following can not be detected by the compiler. You will receive an error/exception at run-time (when the program is run).

    Hashtable ht = new Hashtable();
    ht.Add("key", "string");
    // the compiler does not know what is stored in the hashtable
    // under the key "key"
    int i = (int)ht["key"];  // --> exception at run-time
    
    0 讨论(0)
  • 2020-11-22 07:27

    In simply word difference b/w Compile time & Run time.

    compile time:Developer writes the program in .java format & converts in to the Bytecode which is a class file,during this compilation any error occurs can be defined as compile time error.

    Run time:The generated .class file is use by the application for its additional functionality & the logic turns out be wrong and throws an error which is a run time error

    0 讨论(0)
  • 2020-11-22 07:29

    Hmm, ok well, runtime is used to describe something that occurs when a program is running.

    Compile time is used to describe something that occurs when a program is being built (usually, by a compiler).

    0 讨论(0)
  • 2020-11-22 07:29

    Run time means something happens when you run the program.

    Compile time means something happens when you compile the program.

    0 讨论(0)
  • 2020-11-22 07:30

    The major difference between run-time and compile time is:

    1. If there are any syntax errors and type checks in your code,then it throws compile time error, where-as run-time:it checks after executing the code. For example:

    int a = 1 int b = a/0;

    here first line doesn't have a semi-colon at the end---> compile time error after executing the program while performing operation b, result is infinite---> run-time error.

    1. Compile time doesn't look for output of functionality provided by your code, whereas run-time does.
    0 讨论(0)
提交回复
热议问题