Click here to Skip to main content
15,895,423 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Does a phone interview ever leave you confident... Pin
DaveAuld20-Nov-15 19:53
professionalDaveAuld20-Nov-15 19:53 
GeneralRe: Does a phone interview ever leave you confident... Pin
glennPattonWork321-Nov-15 0:17
professionalglennPattonWork321-Nov-15 0:17 
GeneralWSO CCC OTD 2015-11-10 - Solution. Pin
OriginalGriff10-Nov-15 2:11
mveOriginalGriff10-Nov-15 2:11 
GeneralRe: WSO CCC OTD 2015-11-10 - Solution. Pin
super10-Nov-15 2:37
professionalsuper10-Nov-15 2:37 
GeneralRe: WSO CCC OTD 2015-11-10 - Solution. Pin
pkfox10-Nov-15 3:54
professionalpkfox10-Nov-15 3:54 
GeneralRe: WSO CCC OTD 2015-11-10 - Solution. Pin
908236510-Nov-15 5:43
908236510-Nov-15 5:43 
GeneralRe: WSO CCC OTD 2015-11-10 - Solution. Pin
OriginalGriff10-Nov-15 6:12
mveOriginalGriff10-Nov-15 6:12 
NewsLearnt something "new" about C/C++ PinPopular
Afzaal Ahmad Zeeshan10-Nov-15 1:15
professionalAfzaal Ahmad Zeeshan10-Nov-15 1:15 
I am going to have an exam of C++ tomorrow, so I thought why not just open the book, swap pages from one to the last one, then close it and go back to Haskell once again. But while I did, I asked myself "Are arrays actually consecutive in memory?".

Along with that, I came to another question, "Why is a[5] == 5[a]?" that was something I never knew about before. So, I went searching for the answers and tried it on my own machine too, to make my mind actually believe that I was accessing the ath element of array 5. Laugh | :laugh:
C++
int main()
{
   int a[5] = {1, 2, 3, 4, 5};
   for (int i = 0; i < 5; i++) {
      std::cout << i[a] << ", "; 
   }
   std::cout << std::endl;
   system("pause");
   return 0;
}
// Output: 1, 2, 3, 4, 5,

For those who didn't know it (just like me!) the logic is that C (or C++) translates a[5] to (a + 5) and then gets the data from that location. Which, is similar to having 5[a] that gets translated to (5 + a). Mathematically, we know 5 + a == a + 5. Thus, compiler accepted that.

I hope, I am not alone who didn't know it yet. Laugh | :laugh: I can say I know nothing of C or C++.

For those who want to read a thread, head over to http://stackoverflow.com/questions/381542/with-c-arrays-why-is-it-the-case-that-a5-5a?rq=1[^].
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~

GeneralRe: Learnt something "new" about C/C++ PinPopular
OriginalGriff10-Nov-15 1:25
mveOriginalGriff10-Nov-15 1:25 
GeneralRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 1:28
professionalAfzaal Ahmad Zeeshan10-Nov-15 1:28 
GeneralRe: Learnt something "new" about C/C++ Pin
Super Lloyd10-Nov-15 1:30
Super Lloyd10-Nov-15 1:30 
GeneralRe: Learnt something "new" about C/C++ Pin
fglenn11-Nov-15 7:45
fglenn11-Nov-15 7:45 
GeneralRe: Learnt something "new" about C/C++ Pin
onemorechance15-Nov-15 8:19
onemorechance15-Nov-15 8:19 
GeneralRe: Learnt something "new" about C/C++ Pin
Tim Carmichael10-Nov-15 2:57
Tim Carmichael10-Nov-15 2:57 
GeneralRe: Learnt something "new" about C/C++ Pin
Mike Hankey10-Nov-15 3:32
mveMike Hankey10-Nov-15 3:32 
GeneralRe: Learnt something "new" about C/C++ Pin
Jochen Arndt10-Nov-15 1:26
professionalJochen Arndt10-Nov-15 1:26 
GeneralRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 1:28
professionalAfzaal Ahmad Zeeshan10-Nov-15 1:28 
GeneralRe: Learnt something "new" about C/C++ Pin
Super Lloyd10-Nov-15 1:27
Super Lloyd10-Nov-15 1:27 
GeneralRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 1:29
professionalAfzaal Ahmad Zeeshan10-Nov-15 1:29 
GeneralRe: Learnt something "new" about C/C++ Pin
Sander Rossel10-Nov-15 2:14
professionalSander Rossel10-Nov-15 2:14 
JokeRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 3:11
professionalAfzaal Ahmad Zeeshan10-Nov-15 3:11 
GeneralRe: Learnt something "new" about C/C++ Pin
Sander Rossel10-Nov-15 5:02
professionalSander Rossel10-Nov-15 5:02 
GeneralRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 7:15
professionalAfzaal Ahmad Zeeshan10-Nov-15 7:15 
GeneralRe: Learnt something "new" about C/C++ Pin
Sander Rossel10-Nov-15 9:05
professionalSander Rossel10-Nov-15 9:05 
GeneralRe: Learnt something "new" about C/C++ Pin
Afzaal Ahmad Zeeshan10-Nov-15 9:11
professionalAfzaal Ahmad Zeeshan10-Nov-15 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.