Open In App

Print Function in C, C++, and Python

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: 



Below is the C program printing the inside printf:




// C program printing inside printf()
  
#include <stdio.h>
  
// Driver Code
int main()
{
    // Stores no of characters printed by printf
    int val = printf("GeeksForGeeks\n");
    
    // Print the count of characters
    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++ program printing inside cout
  
#include <iostream>
using namespace std;
  
// Driver Code
int main()
{
  
    // Store no of characters printed by printf
    int value = printf("GeeksForGeeks\n");
    
    // Prints the count of the characters  
    cout << "Integer printf(\"GeeksForGeeks\\n\") = "
         << value << endl;
}

Output
GeeksForGeeks
Integer printf("GeeksForGeeks\n") = 14

Explanation:

Below is the python program illustrating print():




# Python program illustrating print()
  
# Storing value
value=print("GeeksForGeeks\n")
  
# Printing value
print(value)

Output
GeeksForGeeks

None

Explanation: In python3, Print function never returns anything that’s why it is returning None.


Article Tags :