Q56 What is meaning of run time error and compile time error in C?

Complie time error – An error which is identified at compile time is called compile time error.

Below program will give compile time error:

#include<stdio.h>

int main()

{

        int const *num = 100; /* Here num is a pointer to const integer */

        ++(*num); /* Illegal operation, the value of num cannot modify */

         return 0;

}

When we compile above program it gives below compile time error:

copile_time_error.c:5:2: error: increment of read-only location ‘*num’

  ++(*num);

 

Run time error – An error which is not caught by compiler but encountered with while executing the program. Below program will give run time error:

#include<stdio.h>

int main()

{

main();

return(0);

}

When we run this program the main function calls itself again and again. Each time the function is called its return address is stored in the call stack. Since there is no condition to terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error. This is “Runtime error: Stack overflow.”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.