README.md
December 4, 2022 ยท View on GitHub
Description
Logical Bug in C++. C++ contradicts its own errors by saying that p is a constant, and in the next line says that p is not a constant.
More Info
| Submitted On | |
| By | Nitin Gupta |
| Level | Beginner |
| User Rating | 4.7 (42 globes from 9 users) |
| Compatibility | C++ (general), Borland C++ |
| Category | Coding Standards |
| World | C / C++ |
| Archive File |
Source Code
Consider the following program
#include <iostream.h>
#include <conio.h>
void main()
{
int n;
cin>>n;
const int p = n;
p++; // C++ gives error that p is a const
int a[p]; // C++ gives error that p is not a const
}
Now how can c++ give an error for p being a constant in first commented line and also an error for p not being a constant in the second commented line.....logical huh? And the program compiled perfectly till the line
const int p=n;
(This line is accepted).
Anyone with a way out, plz write a message. And if u feel that this discovery is worth a credit, plz vote.