What is the signature of printf?

前端 未结 3 356
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 15:46

Recently in an interview I was asked about what the signature of printf is. I really couldn\'t get a right answer. Would someone be able to shed some light on this?

3条回答
  •  借酒劲吻你
    2020-12-03 16:16

    int printf ( const char * format, ... );
    

    They were probably asking this to see if you were familiar with the optional parameter syntax "...". This allows you to pass an indeterminate list of variables that will fill in the format string.

    For example, the same method can be used to print things like this:

    printf("This is a string: %s", myString);
    printf("This is a string: %s and an int: %d", myString, myInt);
    

提交回复
热议问题