Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 




vprintf() - I/O Function


Tutorials Cpp

Topic

How is "vprintf()" used in C++?



Explanation

vprintf() is an I/O function that writes the contents of the format string to the stdout with a pointer to a list of arguments replacing the argument list. The total number of characters are returned by this function, but on failure a negative number is returned.

Syntax:
    int vprintf ( const char * format, va_list arg );

The following table lists the type specifier used with vprintf()

Type Description
c Character
d or i Signed decimal integer
e Scientific notation using e character
E Scientific notation using E character
f Decimal floating point
g Use the shorter of %e or %f
G Use the shorter of %E or %f
o Signed octal
s String of characters
u Unsigned decimal integer
x Unsigned hexadecimal integer
X Unsigned hexadecimal integer(capital)
p Pointer address
% A % followed by another % character will write % to the stream.

Example:

   #include <stdio.h>
   #include <stdarg.h>
   
   void Form (char * format, ...)
    {
      va_list args;
      va_start (args, format);
      vprintf (format, args);
      va_end (args);
    }
   
   int main ()
    {
      Form ("Function with %d variable argument.\n",1);
      Form ("Function with %d variable %s.\n",2,"arguments");
      return 0;
    }

Result:
    Function with 1 variable argument.
    Function with 2 variable arguments.

In the above example vprintf() is used to call a function with different number of arguments.










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting