C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 14)
                   
                                       
                                14.
What will be the output of the program ?
 
                                    #include<stdio.h>
int main()
{
    char *str;
    str = "%d\n";
    str++;
    str++;
    printf(str-2, 300);
    return 0;
}
Discussion:
43 comments Page 5 of 5.
                
                        Sunitha said: 
                         
                        1 decade ago
                
                Thank you very much archana.
                
                        Archana said: 
                         
                        2 decades ago
                
                Twice str is incremented n then when we do str-2, it is again pointing to starting position. So str contains "%d\n".
So printf statement would be like printf("%d\n",300);
Hence output will be 300.
                So printf statement would be like printf("%d\n",300);
Hence output will be 300.
                        Vijay said: 
                         
                        2 decades ago
                
                Hi guys,
 
Can anyone give the explanation for this problem?
                Can anyone give the explanation for this problem?
Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers