By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

how to get rid of Illegal structure operation?

P: 4
The question is to write C++ program using a function ( is_sorted() ) which takes a 1-D array and size as arguments, returns 1 if it is in ascending order, -1 if in descending order or else 0.
I used int* a[10]; as i was getting an error with just int a[10] when calling the function, can anyone explain to me why i need int* and mostly how to get rid of the illegal structure operation?

This is my code:
int is_sorted(int a[10], int n)
{int ct1=0, ct2=0;
for(int i=0;i<n;++i)
else if(a[i]>=a[i+1])
return 1;
else if(ct2==n)
return -1;
else return 0;

void main()
{int n;
int* a[10];
cin>>n; //the number of elements in an array
for(int i=0;i<n;++i) //to enter the array
cin>>a[i]; //the error
is_sorted(a[10], n);
Feb 7 '16 #1
Share this Question
Share on Google+
1 Reply

P: 4
nvm got it
corrections: (under main)
int n, a[10];
for(int i=0;i<n;++i)
Feb 7 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.