Simple Question
-
char t1[12] ="Codeproject"; char t2[3]; strcpy(t2,t1); AfxMessageBox(t2) what'll be the output?? thanx V
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.
-
char t1[12] ="Codeproject"; char t2[3]; strcpy(t2,t1); AfxMessageBox(t2) what'll be the output?? thanx V
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.