C Programming - Different signature problem with extern variables
One of my friend asked me this question few days back which seemed to be very interesting for me atleast. The question was as followsFile1.c | File2.c | |
1 int arr[80]; |
|
What will be the output when complied and linked together?
It was surprising for me to see a segmentation fault for this kind of a code. Even though array and pointers are different in aspects like
1. Array variable is const pointer
2. Array size has to be defined while declaring the variable
Still I thought array will be manipulated like a pointer, but here in this case what is happening is when we are putting the value 100 to arr[1] it taking the value of the pointer here in this case 0 as arr[80] will be filled with zeros and then adding one to that which mean resulting value will be 0x4 as it is a pointer addition. After that it is trying to put 100 into the address pointed by 0x4 which results in a segmentation fault.
I don't have a sincere justification for this other than explaining why it is working like this. If anyone have any response please post it as a comment.
Labels: C
Posted by - at 8:18 am | 3 comments read on
Window - 013 Windows XP Commands
Some nice Windows XP commands1. Merge two files into another - copy smalefile1 + smallfile2 largefile
2. Decompress Files - extract
3. pushd and popd same as that for bash.
4. Associate a folder to a drive - subst X: C:\windows
5. tree structure for directory - tree
6. find files or find string with in a file - find/findstr
7. Hiding files within another file(NTFS Filesystem Specific) - type 1.jpg > 1.txt:hidden.jpg
8. Alias a command - doskey ls=dir
9. Starting Add/Remove Programs - appwiz.cpl
10. Show listening process and prot - netstat -no|findstr "LISTEN"
Labels: Win32
Posted by - at 1:06 am | 0 comments read on