Difference between Compile-time, Run-time and Logical errors in C (hands-on) | C Programming
Vložit
- čas přidán 25. 08. 2024
- Compile-time vs. Runtime vs. Logical errors in C programming.
In this video, I will explain the difference between compile-time error, runtime error, and logical error in C programming. By the end of this video, you should be able to differentiate between these 3 types of errors in C.
There are different types of errors in C - Compile time error, run-time error, and logical errors.
Compile-time errors as the name say - occur during the compilation process. One best example of a compile-time error is a syntax error. Let’s say, you use printffs (typo) for printing text on the screen. If you try to compile your code, the C compiler will throw an error saying the program could not be compiled as it could not recognize printffs keyword. This is called compile-time error.
Run time error occurs during the execution of the program. It can cause the program to crash if not handled during the coding process. The classic example is division by zero. If your code has division operation and if division by zero is not handled inside the code, the program will compile without any issue. However, if during program execution, the denominator turns out to be zero, the program will crash as division by zero is not a legal operation.
Then we have a logical error. Logical error deals with the logic of the program code. Let’s say, I am writing a code that calculates an average of 3 numbers. The formula to calculate the average is (a+b+c)/3. However, while writing the code, I wrote (a+b)/3 instead of (a+b+c)/3. On compilation, the program will compile successfully and on execution, it will execute perfectly fine without throwing any run-time error. However, the calculation of the average of 3 numbers will be calculated incorrectly. Here, the logic written for calculation is incorrect. This is called logical error. This type of error will not make your program terminate unexpectedly. It will just add a bug in your program code which will result in unexpected output.
Some helpful resources ##
C programming course for beginners - www.aptuts.com...
Learn C programming online for FREE - www.learnconli...
Follow me on my Facebook page - aptuts
Free C programming cheatsheet - www.aptuts.com...
#aptuts #CProgramming #ErrorsInC
Superb and nice explanation
Thank you 🙂
So basically, compile time is when the program is checked for logical and syntactical consistency, and runtime is the actual execution of the program as you use it. Thanks.
I would not say logical consistency... Logical consistency deals with the programming logic and it is something that depends on the developer. Compile time is more about syntactical consistency...
Interested in learning C programming language? Visit my comprehensive C course - www.aptuts.com/c-programming
short and crisp lecture... so satisfied
Thank you
thnx for explaining in a quite simple way..👍
Concept clear.
It helped me a lot!!!!!! thnx.
very well explained
Nice class
thank you bro, crisp and clear explanation.
Thank you :)
Very nice explaination 👍
Thank you 😃
Bro please make videos on C programming ,Java,python it will be really helpful! And btw the video was really nice 👍
THANK U SIR
Very well explained.
Mujhe ek chij janni hai ki jab hum program ke ek ek line code likhte hai to kya wo uss hi time pe compile ho jata hai ya fir pura program likhne ke baad compile hota hai?
Please help me to clear my doubt.🙏
Waiting for your reply.
The program gets compiled as soon as we instruct the code editor (IDE) to compile the code. It is possible to compile the code whenever we want. The code will not get compiled automatically. We have to instruct C compiler to compile it. We can do it after writing 1 line or we can compile the code after writing 5 lines of code. It is totally up to us when to compile.
@@aptuts thank you for the answer
Thanks
Helpful Lecture ❤️
Thank you 👍
Thank you for sharing your kind information🧡
Thanks!
Welcome!
Hai sir ,i have an one dout .why over riding is called as run time polymorphism?.why it's not told as compile time polymorphism?.what is the difference between together?..please advice me sir
Thank you sir
You are welcome! I am glad you found this video helpful.
Sirwhy it will take time to run
Void main()
{
Main()
}
Hello... the above code will run indefinitely or until your computer run out of memory. Here in this case, inside main() you have a function call to main(). This will create indefinite loop and that is the reason why it is taking time for your program to end the execution.
Op video 🔥🔥🔥
Is it same for cpp??
Yes… it works the same
It takes nearly 7...to 8...sec
Sir,how to find a logical erorr in run time
You won’t be able to find the logical error during run time as logical error won’t throw any error during run time. The only is to check the results after run time and compare it with the expected results.
Upload vedios on data structures bro.....
Thank you for your suggestion. Will definitely plan to work on it. 👍🏻
Can compile time and run time errors occurs together in any case
No. Compile time and run time errors can't happen together. Reason being, when ever we try to run a program, it is compiled first. If compilation process is successful then C compiler will create an executable and program is executed. Run time error occurs during run time.unless and until program is compiled successful, program won't run.
Very nice explanation. where are you from sir?
Thank you so much. I am from India :)
nice
:)
Glad you liked it 😊
@@aptuts yes😀