C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 12)
                   
                                       
                                12.
What will be the output of the program?
 
                                    #include<stdio.h>
int main()
{
    int i=2;
    printf("%d, %d\n", ++i, ++i);
    return 0;
}
Answer: Option
                                                    Explanation:
                                                The order of evaluation of arguments passed to a function call is unspecified.
Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.
In TurboC, the output will be 4, 3.
In GCC, the output will be 4, 4.
Discussion:
43 comments Page 1 of 5.
                
                        Usha said: 
                         
                        3 years ago
                
                But its prints the latest value 4, 4 only. Am I right?
                
                        Piyush Watmode said: 
                         
                        4 years ago
                
                Actully, the output in gcc compiler is 4, 4.
                
                     (1)
                
            
                        Ganesh said: 
                         
                        7 years ago
                
                I am not getting it. Please explain me.
                
                     (1)
                
            
                        Giriprasad said: 
                         
                        8 years ago
                
                It is prinetd in left to right. If it is printed in right to left then the output is 3, 4.
                
                     (2)
                
            
                        Salim shaikh said: 
                         
                        8 years ago
                
                Main
{
int I=23;
int J
J=I++;
Printf(",,...d",J);
}
Please tell me in this case why error occurs?
                {
int I=23;
int J
J=I++;
Printf(",,...d",J);
}
Please tell me in this case why error occurs?
                        Sathya said: 
                         
                        8 years ago
                
                int j=5,s=5,i=0,m=5,n=5,q=0,h=5;
i=m++ + ++n-j-- - --s;
q=h++ + ++h - h-- - --h;
System.out.println("q:"+q);
System.out.println("i:"+i);
System.out.println("j:"+j);
System.out.println("s:"+s);
System.out.println("j:"+m);
System.out.println("s:"+n);
can you explain this one?
                i=m++ + ++n-j-- - --s;
q=h++ + ++h - h-- - --h;
System.out.println("q:"+q);
System.out.println("i:"+i);
System.out.println("j:"+j);
System.out.println("s:"+s);
System.out.println("j:"+m);
System.out.println("s:"+n);
can you explain this one?
                        Ramkumar said: 
                         
                        8 years ago
                
                in turbo C o/p is 4,3.
in c++ o/p is 3,4.
in GCC o/p is 4,4.
Thus the answer will be option D : output will vary from compiler to compiler.
                in c++ o/p is 3,4.
in GCC o/p is 4,4.
Thus the answer will be option D : output will vary from compiler to compiler.
                        Kartheek said: 
                         
                        9 years ago
                
                In Linux 4,4 because the priority is from right to left. If pre-increment is there from right to left then the variable is updated.
                
                        Ankit kumar said: 
                         
                        9 years ago
                
                It is mentioned here that in GCC compiler output will be 4 4. How? Explain please.
                
                        Pavani said: 
                         
                        1 decade ago
                
                Sorry displayed in right to left order.
                Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers