I have a program for adjacency matrix implementation in C++.
Here is my code-
#include<iostream>
using namespace std;
void addEdge(int * add){
cout<<"Edge added successfully.\n";
*add = 1;
}
int main(){
int vertex;
cout<<"Enter number of vertices in the graph: ";
cin>>vertex;
int adjMat[vertex][vertex];
for(int i=0;i<vertex;i++){
for(int j=0;j<vertex;j++){
adjMat[i][j] = 0;
}
}
cout<<"\n";
cout<<"Add edges (from and to): ";
int from,to;
while(cin>>from>>to){
if((from >= vertex || from < 1) || (to >= vertex || to < 1)){
cout<"Warning: Out of bound index.\n";
}else{
addEdge(&adjMat[--from][--to]);
}
}
cout<<"\n";
for(int i=0;i<vertex;i++){
for(int j=0;j<vertex;j++){
cout<<adjMat[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
In my program, by mistake, I wrote an error and compiled the program but the dev C++ compiler is not giving error for that and the program is running fine.
Here is that part-
while(cin>>from>>to){
if((from >= vertex || from < 1) || (to >= vertex || to < 1)){
cout<"Warning: Out of bound index.\n";
}else{
addEdge(&adjMat[--from][--to]);
}
}
I am getting the correct error message from other compilers.