Saturday, August 20, 2016

hidden facts of printf() statement

printf() statement is used to print the message as well as values of the variable, but some hidden facts for printf() statements are:

1. The return type of printf() statement are integer i.e the number of character printed by the printf statement.
     Example:  printf("%d","printf("Hello")); will print 5
2. If we do not provide variable name with the printf statement like printf("%d"); , Then the printf statement print the value which is in top of the stack of the memory.
    Example:
    void main()
    {
         int a=100,b=78;
         printf("%d");
}
you feel that it is the wrong or syntax error, but it will print the latest value which is on top of the stack that is 78

No comments:

Post a Comment