Wednesday, October 17, 2012

What is the retrun-type of printf

About printf:    
printf is the formatted print routine that comes as part of the standard C library. the first argument to print is a format string. it describes how any remaining argument are to be printed. The charater % begins a print specification for an argument. In our program, %d told printf to interpret and print the next argument as a decimal number. printf can also output literal characters. In our program, we "printed" a newline character by giving its name (\n) in the format string. 
-----------------------------------------------------------------------------------------------
#include <stdio.h>

int main()
{
    int a = 57;
    printf ("\n");
   
    //What is the output of this

    printf ("%d ");    // This gives garbage value
    printf ("\n\n");    //this is used only to get clear output
   
    //What is the output of this
    printf ("%d",printf("%d",56));  //without space
    printf ("\n\n");
   
    //What is the output of this

    printf ("%d",printf("%d ",56));
    printf ("\n\n");
   
    //What is the output of this
    printf ("%d",printf("%d ",a));
    printf ("\n\n");
   
    //What is the output of this
    printf("%d ",printf("%d ",printf("%d ",56))); //that's very interesting
    printf ("\n\n");
   
    //What is the output of this
    printf ("%d \t %d ",58, a);               // 'space' -->takes 1 character
    printf ("\n\n");
   
    //What is the output of this
    printf("%d",printf ("%d \t %d ",58, a));  // \t -->takes 1 character
    printf ("\n\n");
   
    //What is the output of this
    printf("%d",printf ("%d\n\t %d ",a,59));  // \n -->takes 1 character
    printf ("\n");
   
    return 0;
}


OUTPUT:

No comments:

Post a Comment