Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Printf() function inside another Printf(function)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 482
    Comment on it

    What happens when you use a printf() function inside another printf() function. To understand this lets see the following example:

    #include<stdio.h>
    int main() {
      int number = 1234;
      printf("%d", printf("%d", printf("%d", number)));
      return(0);
    }
    

    Output:

      123441
    

    Explanation of the above program::

    1. The "innermost" printf() function prints the value of the number i.e., "1234"

    2. The second printf() function will now be as

      printf("%d", 4); 

      it's because the first printf() function will return 4 as the total number of digits in original "number" and it will print "4".

      The output will now be "12344"

    3. The last printf() fiunction will now be as

      printf("%d", 1);

      it's because the second printf() function will return 1 as the total number of digits(i.e., 4 is a single digit number) and it will print "1".

      The output will now be "123441".

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: