Practical 5 - CSU1128P - CSE 2026 - Shoolini University

Write about compile time and runtime errors with an example.

Compile Time Errors

Occur when the program does not conform to the language's syntax rules.
Are detected during compilation before the program is executed.
Generally results from a typo or a wrong statement in the code.
It Can be easily identified and fixed by looking at the compiler's error messages.
Do not cause any harm to the system.

Let us look at an example of compile time error.

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128P)
 * Instructor: Abdullahi Adem | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>
int main() {
    int a = 1;
    int b = 2;
    int c = a + b
    return 0;
}
                    
                

Output

gcc /tmp/gnqKaOW3lQ.c -lm
/tmp/gnqKaOW3lQ.c: In function 'main':
/tmp/gnqKaOW3lQ.c:5:3: error: expected ',' or ';' before 'return'
  5 | int c = a + b
    | ^~~

Run Time Errors

Occur when the program runs, and there is an unexpected result due to incorrect logic or input data.
Are detected during execution after the program has started running.
Generally result from a logical mistake or invalid input data.
It Cannot be easily identified and fixed by looking at the compiler's error messages.
Can cause harm to the system, such as crashing programs or corrupting data.

Let us look at an example of run time error.

                        
/* *
 *
 *  Logic Building with Computer Programming (CSU1128P) by Dr. Pankaj Vaidya and Abdullahi Adem
 *
 *  This program contains all the programs done in the course
 *  Logic Building with Computer Programming with the course code CSU1128.
 *
 *  DO NOT COPY
 *  DO NOT REPRODUCE
 *  DO NOT MODIFY
 *
 *  (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 *
 * */

#include <stdio.h>
int main() {
    int a = 1;
    int b = 2;
    int c = a + b;
    int d = c / 0;
    return 0;
}
                    
                

Output

Floating point exception

Difference between Compile time and run time errors.

Compile time errors occur when the code is being compiled, while run time errors occur when code is being executed.
Compile time errors are usually syntax errors and can be easily identified and fixed, while run time errors are more difficult to debug.
Compile time errors prevent the code from being executed, while run time errors can occur after the code has been successfully compiled.
Compile time errors are usually detected by the compiler, while run time errors are usually detected by the program itself.
Compile time errors can be fixed by simply correcting the code, while run time errors often require more in-depth debugging and analysis.