Saturday 13 April 2013

Operator's tricky program 11


What will be output of the following program?

#include<stdio.h>
int main(){
    float a;
    (int)a= 45;
    printf("%d,a);
    return 0;
}

Explanation
Output:
Turbo C++ 3.0: Compilation error
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error

Explanation:
After performing any operation on operand it always return some constant value.

(int) i.e. type casting operator is not exception for this. (int) a will return one constant value and we cannot assign any constant value to another constant value in c.

(int)a = 45; is equivalent to
3456 = 45 ( Here 3456 in any garbage value of int(a)).

No comments:

Post a Comment