Asim
HUSANOVIĆ

Tag: windows

admin
NVIDIA Interview Question for Software Engineer in Tests
2012.06.29 12:45:19

Give output for for the following code

#include
#include
 
int main(int argc, char *argv[])
{
int i=5;
printf("%d ", i++ + ++i);
printf("%d ", i++ + ++i + i++ + ++i);
printf("%d ", ++i + i++ + ++i + i++);
 
system("PAUSE"); 
return 0;
}

Answer:

#include
#include
 
int main(int argc, char *argv[])
{
int i=5;
printf("%d ", i++ + ++i); // 5 + 1 + 5 + 1 = 12 (i=7)
printf("%d ", i++ + ++i + i++ + ++i); // 7 + 1 + 7 + 8 + 1 + 9 + 1 + 1 = 33 (i=11)
printf("%d ", ++i + i++ + ++i + i++); // 1 + 11 + 12 + 1 + 12 + 12 + 1 = 50 (i=15)
 
system("PAUSE"); 
return 0;
}

 



Tags: linux | windows | c/cpp

Hits: 2887 | Read more...


 

IDOBlog - blog for joomla 1.5