Illegal Operation meaning.....

Nov 4, 2010 at 7:39am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include"iostream.h"
#include"conio.h"

const int ch = 5;

void main()
{
 clrscr();
 
 int *p[ch];

 for(int j=0 ;j<ch; ++j)
     *p[j]=j;
 for(j=0 ;j<ch; ++j)
     cout<<*p[j];

 delete p;
 getch();
}



012345


But after this a message comes
"The NTVDM CPU has encountered an illegal instruction
Choose 'Close to terminate the application.'"

What is the reason behind it ????
Is it something related to pointer declaration????
Please help me out...ASAP :)
Thnx
Nov 4, 2010 at 7:58am
Is it something related to pointer declaration????


Nope, it's something to do with the pointer deletion.

Since you declared an array, delete p; should be delete [] p;
Nov 4, 2010 at 3:14pm
closed account (D80DSL3A)
Don't delete anything. You never used new! Try omitting line 17.
Nov 4, 2010 at 3:24pm
Several other things.

#1: Ye've gat the rong stayle of #include, dere, at least fer iostream. (replace "" with <>)

#2: conio.h is severely deprecated, and for a good reason, too. I suggest you don't use it.

#3: The standard commands that you use int main() in place of void main(). g++ won't even compile that.

#4: @Line 15: I never saw any using, and never any scope resolution operators with std on the left-hand side.

What compiler are you using!?! If it claims to be a C++ compiler and it actually did compile this code, drop it right away and switch to the newest version of g++ or Visual Studio! The bird-brain commands it!

-Albatross

EDIT: WTF? How did I end up with 2 2s?
Last edited on Nov 4, 2010 at 9:19pm
Nov 4, 2010 at 3:35pm
#5: Why is 'p' an array of pointers instead of an array of ints? What are they pointing to? You probably should change to this:

1
2
3
4
 int p[ch];  // no need for pointers

 for(int j=0 ;j<ch; ++j)
     p[j]=j;  // no need for dereference operator 

Topic archived. No new replies allowed.