Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Application crash

Application crash

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    udayGovekar
    wrote on last edited by
    #1

    Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday

    M J S 3 Replies Last reply
    0
    • U udayGovekar

      Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday

      M Offline
      M Offline
      Mike Nordell
      wrote on last edited by
      #2

      'ch' is an unspecified type. Please repost what your code really looks like.

      U 1 Reply Last reply
      0
      • M Mike Nordell

        'ch' is an unspecified type. Please repost what your code really looks like.

        U Offline
        U Offline
        udayGovekar
        wrote on last edited by
        #3

        Sorry, Char ch;

        A 1 Reply Last reply
        0
        • U udayGovekar

          Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday

          J Offline
          J Offline
          Jason Henderson
          wrote on last edited by
          #4

          use ptrChar = new char then delete ptrChar You should always delete what you create with new. Setting ptrChar to NULL after deleting is good practice if you may use ptrChar later.

          Jason Henderson
          quasi-homepage
          articles
          "Like it or not, I'm right!"

          1 Reply Last reply
          0
          • U udayGovekar

            Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday

            S Offline
            S Offline
            Sharad Ganesh
            wrote on last edited by
            #5

            hi, Assigning a pointer to NULL does not actually free the allocated memory. Your memory should have been allocated by using "new char". ch is not any type here. I presume it should have been "char". One very nice thing about delete is that even if the pointer = NULL, ur app _won't_ crash. I just replace that new ch with "new char". and then delete ptrChar; Regards, Sharad Ganesh

            U 1 Reply Last reply
            0
            • S Sharad Ganesh

              hi, Assigning a pointer to NULL does not actually free the allocated memory. Your memory should have been allocated by using "new char". ch is not any type here. I presume it should have been "char". One very nice thing about delete is that even if the pointer = NULL, ur app _won't_ crash. I just replace that new ch with "new char". and then delete ptrChar; Regards, Sharad Ganesh

              U Offline
              U Offline
              udayGovekar
              wrote on last edited by
              #6

              hi, memory is allocated using new but still when I am trying to delete, it is getting crashed Uday

              S 1 Reply Last reply
              0
              • U udayGovekar

                Sorry, Char ch;

                A Offline
                A Offline
                Alexandru Savescu
                wrote on last edited by
                #7

                you should do this:

                char *ptrChar;
                ptrChar= new char;
                *ptrChar = 'c';
                ''
                '' some logic here
                ''
                delete ptrchar;

                Best regards, Alexandru Savescu

                1 Reply Last reply
                0
                • U udayGovekar

                  hi, memory is allocated using new but still when I am trying to delete, it is getting crashed Uday

                  S Offline
                  S Offline
                  Sharad Ganesh
                  wrote on last edited by
                  #8

                  hi, Did u check up on the corrected code i posted ? There was a corection "new char". Rgds, Sharad

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups