I wrote 2 c program in which I got two different output but I didn't change the operation the 1st program is with scanf and 2nd is without scanf

Viewed 34

see these two programs

    //**code 1 whithout scanf**
    #include <stdio.h> 
    int main() 
    { 
        int a=3;
        int b = ++a + ++a;
        printf("%d",b);
    } 

output is 10

//**code 2 with scanf**

    #include <stdio.h> 
    int main() 
    { 
        int a;
        scanf("%d",&a);
        int b = ++a + ++a;
        printf("%d",b);
    } 

input value is 3 got output value is 9

in first program a is initialized with 3 then output is 10 but in second program I scan the value of a i.e. 3 but the output is 9 and in both program I did the same operation. Then why this so happen?

0 Answers
Related