Javascript

Do You Know What ++i And i++ Really Do?

An interviewer who thinks he is being clever might present you with a code sample like the following and ask you what the output would be:

//C
#include <stdio.h>
 
void dosomething(int i, int j, int k, int l)
{
  printf("%d, %d, %d, %d\n", i,j,k,l);
}
 
int main(int argc, char **argv)
{
  int i =1;
  dosomething(i++, ++i, i++, ++i);
 
  i = 1;
  printf("%d\n", i++ + ++i + i++ + ++i);
 
  i = 1;
  printf("%d\n", (i++) + (++i) + (i++) + (++i));
}

Syndicate content