0
#define MAX 5    
void bfs(int adj[][MAX],int visited[],int start,int order){

    }
    main(){
        int order;
        cin>>order;
        int adj[MAX][MAX];// **Here**
        bfs(adj,visited,0,order);

    }

Why am I getting a compiler error:

cannot convert 'int (*)[order]' to 'int (*)[5]' for argument '1'
            to 'void bfs(int (*)[5], int*, int, int)'

if I replace 2nd dimension of adj with order variable having same value as MAX macro. Would be grateful for any insight.

Have left the function bfs and header files blank intentionally as they are irrelevant.

Here's the full code if it helps..

#include<bits/stdc++.h>
#define MAX 5
using namespace std;
void bfs(int adj[][MAX],int visited[],int start){
    int queue[MAX],rear=-1,front=-1;
    queue[++rear]=start;
    visited[start]=1;
    while(front!=rear){
        start=queue[++front];
        if(front!=rear)
        cout<<(char)(start+65);
        for(int i=0;i<MAX;i++){
            if(adj[start][i]==1 && visited[i]==0){
                queue[++rear]=i;
                visited[i]=1;
            }
        }
    }

}
main(){
    int order;
    int visited[MAX]={0};
    int adj[MAX][order];//here
    cin>>order;
    cout<<"Enter the adjacency matrix\n";
    for(int i=0;i<MAX;i++)
        for(int j=0;j<MAX;j++){
            cin>>adj[i][j];
        }
        bfs(adj,visited,0);

}
  • what's visited in your `main`? – Joseph D. Apr 07 '18 at 08:02
  • 1
    The error doesn't match the code you show. You need to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). And please put a full and complete copy-paste of the error inside the question body when you're editing it, and make sure the error marker is on the correct line. – Some programmer dude Apr 07 '18 at 08:04
  • See if this helps https://stackoverflow.com/questions/34778847/invalid-conversion-from-int-to-int3-c – SaganRitual Apr 07 '18 at 08:04
  • Wait, no, I mean this one https://stackoverflow.com/questions/49312484/error-incompatible-types-in-assignment-of-long-int-4-to-long-int-44 – SaganRitual Apr 07 '18 at 08:09

0 Answers0