Powered By Blogger

Thursday 28 April 2011

Guess why the output is different from the initialized value. Its due to a simple change done while initialization nd with a definite logic.

#include<stdio.h>

#include<conio.h>
int main(void)
{
  int i=012;
  int j=046;
  int k=056;
  printf("i=%d\n",i);
  printf("j=%d\n",j);
  printf("k=%d\n",k);

  getch();

  return 0;
}





LOGIC:

Closely observe the value initialization.

It stats with 0 that means it's a octal number but not a decimal.

When it's printed we get the decimal values of the octal no.

So i becomes 10, y becomes 38, z becomes 46.

2 comments: