C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 11)
                   
                                       
                                11.
What will be the output of the program?
 
                                    #include<stdio.h>
int main()
{
    int x=55;
    printf("%d, %d, %d\n", x<=55, x=40, x>=10);
    return 0;
}
Answer: Option
                                                    Explanation:
                                                
Step 1: int x=55; here variable x is declared as an integer type and initialized to '55'.
Step 2: printf("%d, %d, %d\n", x<=55, x=40, x>=10);
In printf the execution of expressions is from Right to Left. 
here x>=10 returns TRUE hence it prints '1'.  
x=40 here x is assigned to 40 Hence it prints '40'. 
x<=55 returns TRUE. hence it prints '1'.
Step 3: Hence the output is "1, 40, 1".
Discussion:
16 comments Page 2 of 2.
                
                        Asmita said: 
                         
                        7 years ago
                
                @Ranjit.
 
If the statement is true then it returns 1.
If false then 0.
                If the statement is true then it returns 1.
If false then 0.
                        Siva said: 
                         
                        5 years ago
                
                I have a doubt the declaration is x=>55.
My thought is before the 55 is 54 so it must be the answer but why it's 1?
                My thought is before the 55 is 54 so it must be the answer but why it's 1?
                        Rohit L said: 
                         
                        4 years ago
                
                int main()
{
int x=55,a;
printf(" %d, %d, %d\n",x=50, x=40, x>=10);
return 0;
}
the output is 50 50 1
How? Please anyone explain me.
                {
int x=55,a;
printf(" %d, %d, %d\n",x=50, x=40, x>=10);
return 0;
}
the output is 50 50 1
How? Please anyone explain me.
                        Sameer said: 
                         
                        4 years ago
                
                Why expression right to left? 
Please explain to someone.
                Please explain to someone.
                        Shivani said: 
                         
                        3 years ago
                
                Why expression is right to left? please explain to someone.
                
                        Ashok said: 
                         
                        2 years ago
                
                Here the number 40 is not assigned in the program.
But it shows 40 is assigned HOW?
Anyone can explain it in detail.
                But it shows 40 is assigned HOW?
Anyone can explain it in detail.
Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers