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. Simple Question

Simple Question

Scheduled Pinned Locked Moved C / C++ / MFC
question
22 Posts 8 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.
  • E Eytukan

    char t1[12] ="Codeproject"; char t2[3]; strcpy(t2,t1); AfxMessageBox(t2) what'll be the output?? thanx V

    K Offline
    K Offline
    kakan
    wrote on last edited by
    #21

    t1 and t2 are stack variables. Your allocation makes the compiler to reserve memory on the stack for t1 and t2. The order of the allocation is undefined (I think). So if you are lucky, it the stack allocation starts with t2, followed by t1. You copy the content of t1 to t2, including the terminating \0, and nothing happens. Output will be "Codeproject". (If you output t1, it will be "eproject"). If it´s allocated the other way around, it will still output "Codeproject", but your program will likely go bananas when the function terminates, due to the corrupted stack. (The stack also contains the address to return to, usually the address to the function that called the present function). There are a lot of articles about what´s on the stack, written by people with far more knowledge on the subject than myself. If you want accurate info, pls. read those articles.

    1 Reply Last reply
    0
    • E Eytukan

      char t1[12] ="Codeproject"; char t2[3]; strcpy(t2,t1); AfxMessageBox(t2) what'll be the output?? thanx V

      M Offline
      M Offline
      Marc Soleda
      wrote on last edited by
      #22

      Depends on what you do after the code provided ... all after the third character can be overwritten at any time so, this data, is unsecured. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

      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