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. help on good old C

help on good old C

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 6 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.
  • P Offline
    P Offline
    pavansavoy
    wrote on last edited by
    #1

    since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

    D M 4 H R 5 Replies Last reply
    0
    • P pavansavoy

      since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      What exactly are you wanting to know about the two statements?


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      1 Reply Last reply
      0
      • P pavansavoy

        since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

        M Offline
        M Offline
        Micie
        wrote on last edited by
        #3

        int *p; // prepare int pointer for var p p=(int (*)[4])malloc (3*sizeof(*p)); This code is allocating an array for 12 bytes long (3 ints = 12bytes) in memory and returns result to variable p :-O **__________ I'm made in C++... and I'm proud of it!_**

        1 Reply Last reply
        0
        • P pavansavoy

          since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

          4 Offline
          4 Offline
          4apai
          wrote on last edited by
          #4

          this code trully allocate array of three int elements. int *p; p=(int *)malloc (3*sizeof(int));

          1 Reply Last reply
          0
          • P pavansavoy

            since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

            H Offline
            H Offline
            Henry miller
            wrote on last edited by
            #5

            I can't. I'm guessing sixeof is a typo and you ment sizeof. (a forgivable mistake unless you really ment sixeof, in which case I'd need to know more about it) the int (*)[4] part is wrong. It is tyring to tell the compiler that you have an array of 4 ints, but just allocated 3! Not that the compiler would check, it is legal C to then use p[5], though it is undefined behavior and will randomly crash your program. Just write int *p = malloc(3*sizeof(int)); like the rest of us would.

            1 Reply Last reply
            0
            • P pavansavoy

              since no one is online elsewhere, here it goes explain int *p; p=(int (*)[4])malloc (3*sixeof(*p)) please

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #6

              Have a look at this : http://www.codeproject.com/cpp/complex_declarations.asp[^] __________________________________________ a two cent stamp short of going postal.

              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