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. char * & char []

char * & char []

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 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.
  • S Offline
    S Offline
    sarath_babu
    wrote on last edited by
    #1

    What is the difference between char *ptr="babu" char ptr[]="babu" babu

    B R 2 Replies Last reply
    0
    • S sarath_babu

      What is the difference between char *ptr="babu" char ptr[]="babu" babu

      B Offline
      B Offline
      Bob Stanneveld
      wrote on last edited by
      #2

      Nothing... The 2nd declaration is more readable through the program, as it is clear that you are using an array. Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.

      R 1 Reply Last reply
      0
      • S sarath_babu

        What is the difference between char *ptr="babu" char ptr[]="babu" babu

        R Offline
        R Offline
        rrrado
        wrote on last edited by
        #3

        char *ptr -> ptr is pointer to memory, where the string is stored, you can set it later to point to another string. char ptr[] -> array, you can only change string content ... i think shis will consume 4 bytes less memory than first definition :)


        rrrado

        1 Reply Last reply
        0
        • B Bob Stanneveld

          Nothing... The 2nd declaration is more readable through the program, as it is clear that you are using an array. Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.

          R Offline
          R Offline
          rrrado
          wrote on last edited by
          #4

          There is a difference, check the disassembly

          127: char aaa[] = "ssss";
          004B423D mov eax,[string "ssss" (005fd498)]
          004B4242 mov dword ptr [ebp-18h],eax
          004B4245 mov cl,byte ptr [string "ssss"+4 (005fd49c)]
          004B424B mov byte ptr [ebp-14h],cl
          128: char *bbb = "bbb";
          004B424E mov dword ptr [ebp-1Ch],offset string "bbb" (005fd46c)
          129:
          130: char *cc;
          131:
          132: cc = bbb;
          004B4255 mov edx,dword ptr [ebp-1Ch] ; address of string is loaded from memory
          004B4258 mov dword ptr [ebp-20h],edx
          133: cc = aaa;
          004B425B lea eax,[ebp-18h] ; cc just gets address
          004B425E mov dword ptr [ebp-20h],eax


          rrrado

          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