Skip to content
Related Articles

Related Articles

C++ Program to Show Unreachable Code Error

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 25 Jul, 2022
View Discussion
Improve Article
Save Article

Unreachable code is a compile-time error in languages like C++, Java, and C or Unreachable code error occurs when the code can’t be compiled; but why it is just a warning in C++ & C ? Warnings are a way that the compiler indicates that the particular mentioned thing might become an error in future.

Example:

C++




// C++ Program to demonstrate
// Unreacheable Code error
#include <iostream>
using namespace std;
  
int c();
int main()
{
    cout << c() << endl;
    return 0;
}
int c()
{
    int a = 3;
    return a; // oops it is unreachable code
    int b = 6;
    cout << b; // program control never goes here
}

Output

3
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!