Friday 12 April 2013

Operator's tricky Program 7


What will be output of the following program?

#include<stdio.h>
int main(){
    int a;
    a=015 + 0x71 +5;
    printf("%d",a);
    return 0;
}

Explanation
Output: 
Turbo C++ 3.0: 131

Turbo C ++4.5: 131

Linux GCC: 131

Visual C++: 131


Explanation:
015 is octal number its decimal equivalent is = 5 * 8 ^ 0 + 1 * 8 ^ 1 = 5 + 8 = 13
0x71 is hexadecimal number (0x is symbol of hexadecimal) its decimal equivalent is = 1 * 16 ^ 0 + 7 * 16 ^ 1 = 1 + 112 = 113
So, a = 13 + 113 + 5 = 131

No comments:

Post a Comment