Print Function in C, C++, and Python
Last Updated :
08 Mar, 2021
In this article, the task is to observe the behavior of the print function in C, C++, and Python. Print function is used to display content on the screen.
Approach:
- Some characters are stored in integer value inside printf function.
- Printing the value as well as the count of the characters.
- Illustrating the different use of printf().
Below is the C program printing the inside printf:
C
#include <stdio.h>
int main()
{
int val = printf ( "GeeksForGeeks\n" );
printf ( "Int printf(\"GeeksForGeeks\\n \") = %d\n" , val);
return 0;
}
|
Output
GeeksForGeeks
Int printf("GeeksForGeeks\n ") = 14
Below is the C++ program printing inside cout:
C++
#include <iostream>
using namespace std;
int main()
{
int value = printf ( "GeeksForGeeks\n" );
cout << "Integer printf(\"GeeksForGeeks\\n\") = "
<< value << endl;
}
|
Output
GeeksForGeeks
Integer printf("GeeksForGeeks\n") = 14
Explanation:
- In both the above code, printf returns the number of character it has printed successfully.
- “GeeksForGeeks\n” have 14 characters hence it will print 14.
Below is the python program illustrating print():
Python3
value = print ( "GeeksForGeeks\n" )
print (value)
|
Output
GeeksForGeeks
None
Explanation: In python3, Print function never returns anything that’s why it is returning None.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...