The alleged 'proof'
Code:
#include<stdio.h>
/*!!#include<conio.h>*/
#include<string.h>
int main()
{
char arr[10]={"LASERLIGHT"};
printf("%s\n", &arr);
strcat(arr, "ING");
printf("%s\n", &arr);
strcpy(arr, "WHITEFLAG");
printf("%s\n", &arr);
/*!! getch(); */
return 0;
}
$ gcc -g -W -Wall -ansi -pedantic baz.c
baz.c: In function ‘main’:
baz.c:7: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
baz.c:9: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
baz.c:11: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
First thing you need to do is get a decent compiler, then start paying attention to all warning and error messages. Using &array for %s is one of those things which works by accident. Similar mistakes with other types would just blow up.
I'm guessing with the conio.h and getch rubbish that you're still using TurboC. Aside from it's age, it is also remarkably forgiving of memory trashing behaviour, especially in small programs. Hence the "it works for me" comments.
But rest assured, your program is thoroughly broken.
This is what I get, when trying to run your code using valgrind (look it up, start using it)
Code:
$ valgrind ./a.out
==2299== Memcheck, a memory error detector
==2299== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==2299== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==2299== Command: ./a.out
==2299==
LASERLIGHT
LASERLIGHTING
WHITEFLAG
*** stack smashing detected ***: ./a.out terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0x411f390]
/lib/tls/i686/cmov/libc.so.6(+0xe233a)[0x411f33a]
./a.out[0x804853d]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x4053bd6]
./a.out[0x8048411]
======= Memory map: ========
04000000-0401b000 r-xp 00000000 08:15 138613 /lib/ld-2.11.1.so
0401b000-0401c000 r--p 0001a000 08:15 138613 /lib/ld-2.11.1.so
0401c000-0401d000 rw-p 0001b000 08:15 138613 /lib/ld-2.11.1.so
0401d000-0401f000 rw-p 00000000 00:00 0
0401f000-04020000 r-xp 00000000 08:15 207043 /usr/lib/valgrind/vgpreload_core-x86-linux.so
04020000-04021000 r--p 00000000 08:15 207043 /usr/lib/valgrind/vgpreload_core-x86-linux.so
04021000-04022000 rw-p 00001000 08:15 207043 /usr/lib/valgrind/vgpreload_core-x86-linux.so
04022000-04028000 r-xp 00000000 08:15 207048 /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
04028000-04029000 r--p 00006000 08:15 207048 /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
04029000-0402a000 rw-p 00007000 08:15 207048 /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
0402a000-0402b000 rw-p 00000000 00:00 0
0403d000-04190000 r-xp 00000000 08:15 138819 /lib/tls/i686/cmov/libc-2.11.1.so
04190000-04191000 ---p 00153000 08:15 138819 /lib/tls/i686/cmov/libc-2.11.1.so
04191000-04193000 r--p 00153000 08:15 138819 /lib/tls/i686/cmov/libc-2.11.1.so
04193000-04194000 rw-p 00155000 08:15 138819 /lib/tls/i686/cmov/libc-2.11.1.so
04194000-04199000 rw-p 00000000 00:00 0
04199000-04599000 rwxp 00000000 00:00 0
045ac000-045c9000 r-xp 00000000 08:15 132946 /lib/libgcc_s.so.1
045c9000-045ca000 r--p 0001c000 08:15 132946 /lib/libgcc_s.so.1
045ca000-045cb000 rw-p 0001d000 08:15 132946 /lib/libgcc_s.so.1
08048000-08049000 r-xp 00000000 00:15 148056 /home/sc/work/a.out
08049000-0804a000 r--p 00000000 00:15 148056 /home/sc/work/a.out
0804a000-0804b000 rw-p 00001000 00:15 148056 /home/sc/work/a.out
0804b000-0804c000 rwxp 00000000 00:00 0
38000000-3819e000 r-xp 00000000 08:15 207047 /usr/lib/valgrind/memcheck-x86-linux
3819f000-381a1000 rw-p 0019e000 08:15 207047 /usr/lib/valgrind/memcheck-x86-linux
381a1000-38a77000 rw-p 00000000 00:00 0
61d9d000-62a1d000 rwxp 00000000 00:00 0
62a1d000-62a1f000 ---p 00000000 00:00 0
62a1f000-62a2f000 rwxp 00000000 00:00 0
62a2f000-62a31000 ---p 00000000 00:00 0
62a31000-64f83000 rwxp 00000000 00:00 0
beb36000-beb38000 rwxp 00000000 00:00 0
bfb24000-bfb39000 rw-p 00000000 00:00 0 [stack]
==2299==
==2299== HEAP SUMMARY:
==2299== in use at exit: 53 bytes in 1 blocks
==2299== total heap usage: 6 allocs, 5 frees, 989 bytes allocated
==2299==
==2299== LEAK SUMMARY:
==2299== definitely lost: 0 bytes in 0 blocks
==2299== indirectly lost: 0 bytes in 0 blocks
==2299== possibly lost: 0 bytes in 0 blocks
==2299== still reachable: 53 bytes in 1 blocks
==2299== suppressed: 0 bytes in 0 blocks
==2299== Rerun with --leak-check=full to see details of leaked memory
==2299==
==2299== For counts of detected and suppressed errors, rerun with: -v
==2299== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 14 from 9)
Aborted