exit DOS through C?

This is a discussion on exit DOS through C? within the C Programming forums, part of the General Programming Boards category; hi, i have a problem here in this code Code: #include<stdio.h> #include<conio.h> #include<iostream.h> void main() { cout<<*(int *)0xffff; getch(); } ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    10

    Unhappy exit DOS through C?

    hi,
    i have a problem here in this code
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<iostream.h>
    void main()
    {
    
         cout<<*(int *)0xffff;
         getch();
    }
    why DOS stops running after executing this code?
    Please reply after executing this code.

    thanks ..........

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > #include<conio.h>
    This isn't standard C

    > #include<iostream.h>
    This is old-style C++

    > void main()
    This should be int main

    > cout<<*(int *)0xffff;
    This doesn't even compile as C, and is undefined behaviour in C++.

    Now, given that absolutely anything could be happening, what was your question again?

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    10
    Quote Originally Posted by Salem
    > #include<conio.h>
    This isn't standard C

    > #include<iostream.h>
    This is old-style C++

    > void main()
    This should be int main

    > cout<<*(int *)0xffff;
    This doesn't even compile as C, and is undefined behaviour in C++.

    Now, given that absolutely anything could be happening, what was your question again?
    No problem if u run the program whether in c or c++
    it results in same ,it simply turn off the DOS ,BUT why it does so?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Rumor has it that most people around here on this C programming forum with oh... 9000+ posts actually know what they're talking about.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > it results in same ,it simply turn off the DOS ,BUT why it does so?
    Are you trying to suggest that say
    cout<<*(int *)0xfffe;
    Might be OK, do something different, or in any way be any more useful than what you have at present?
    Or that your answer is wholy dependent on the compiler you're using (*)

    For all I know, the actual cause of the problem could be an alignment exception caused by you trying to dereference an int which is on an odd address.

    Perhaps you should learn the language (that's C or C++, not some mythical c/c++) before trying random dumb tricks to crash your box.

    (*) random guesses here suggest you're using Borland TurboC on XP operating system.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  2. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  3. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 08:08 PM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 12:42 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 06:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21