The puts() function in C/C++

The puts() function in C/C++ is used to write a line or string to the output(stdout) stream. It prints the passed string with a newline and returns an integer value. The return value depends on the success of the writing procedure.
The
puts()
function declaration is given below.
int puts(const char* str);
Here,
str
is the constant string that is to be printed.

Let us look at a small example.
#include<stdio.h>
int main()
{
 //string initialisation
    char Mystr[] = "C and C++";
    
    puts(Mystr); //writing the string to stdout
    
    return 0;
}

Output
C and C++

As you can see, our string 
Mystr
has been successfully printed to the 
stdout
The below-given code snippet also yields the same output in C++.
#include<iostream>
using namespace std;
int main()
{
 //string initialisation
    char Mystr[] = "C and C++";
    
    puts(Mystr); //writing the string to stdout
    
    return 0;
}


Posted on by