Printf return value

Printf function is an output function that prints characters to stdout / console / command shell. Printf function returns the number of characters printed to the output file stream(stdout / console / shell).

Printf takes a formatting string and a number of optional arguments. Printf converts these arguments (char, string, int, long, float, double etc) to printable strings and the final constructed string is transferred to the stdout file stream.

Printf block diagram

Printf return value example

#include <stdio.h>

int main()
    int ret;
    /* 11 character string */
    ret=printf("Hello World");
    printf("\nprintf returns %d\n", ret);
    /* 1 character integer */
    ret=printf("%d", 1);
    printf("\nprintf returns %d\n", ret);
    /* 2 character integer */
    ret=printf("%d", 10);
    printf("\nprintf returns %d\n", ret);
    /* 3 character integer */
    ret=printf("%d", 100);
    printf("\nprintf returns %d\n", ret);
    return 0;

Printf return value output

There are 4 printf statements to demonstrate the return value of printf.

Hello World                                                                                                                            
printf returns 11                                                                                                                      
printf returns 1                                                                                                                       
printf returns 2                                                                                                                       
printf returns 3 

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.