Input and output commands: your beginning in programming

Take your first steps in programming. Learn about input and output commands, and how it allows you to communicate with your computer.

11/09/2023

youtube-thumb
algol-youtube-play

Before reaching this article, you must have read our article about algorithms.

Before learning about the input and output commands, it is recommended that you already have a sense of the meaning of the algorithms.

But let’s get down to business!


What does input and output mean?

Every type of computer, from your digital wristwatch to scientific supercomputers, has mechanisms for communicating with the outside world.

  • Mechanisms that take information from outside into the computer (input).
  • Mechanisms that take information from the computer out (output).

For example: if you think about the 3-step model for creating an algorithm (discussed in the previous article), the input represents the 1st step and the output represents the 3rd step.

And there are several ways a computer can get information in (input) and provide information out (output).

Here are some examples:

Your cell phone

Your cell phone is an excellent example of how a computer uses input and output.

The cell phone screen is an example of output

Sound output is another example of output

Screen taps are an example of input

Side buttons are examples of input

The cell phone screen and the music you listen to with your headphones are examples of output, because they are ways of displaying and sending information out of the cell.

Touch recognition and side buttons are examples of input, because they allow you to take information to inside your cell phone.

The ATM

Like your cell phone, the ATM you use to withdraw money is also a good example of input and output mechanisms.

The card reader is an example of an input

The button panel is another example of input

The interface screen is an example of output

The cash dispenser is an example of output

Certainly, it has now become very clear to you the meaning of the input and output.


Computer input and output

In Personal Computers (PCs) the input and output devices are known as input and output peripherals.

See some examples.

Input Peripherals

In summary: the mouse, keyboard, webcam, joystick, microphone, scanner and all devices that send information signals into the computer are the input peripherals.

Output peripherals

In summary: the monitor, the speaker, the headphones, the overhead projectors and all the devices that send information signals out of the computer are the output peripherals.


Standard input and output

Among the computer’s input and output peripherals, there are two that are standard: the keyboard and the monitor, in such a way that modern computers simply don’t work without them:

Keyboard: computer’s standard input

Monitor: the computer’s standard output

If you think about it, you’ll see the logic of it!

We can use the computer without the printer or speakers, but not without the monitor.

Likewise, we can use the computer without a mouse, microphone or webcam, but not without the keyboard!


What does standard input and output have to do with programming?

In your first contact with programming, you will certainly learn to use standard input and output to write your first algorithms!

You go:

  • write commands for the algorithm to print information on the monitor (on standard output).
  • and will write commands for the algorithm to receive values typed on the keyboard by the user (from standard input).

See below the standard input and output commands in the main programming languages.

Java
C
C++
C#
Python
1.import java.util.Scanner;
2.public class Main {
3. public static void main(String args[]) {
4. // standard input command in Java
5. Scanner sc = new Scanner(System.in);
6. int value = sc.nextInt();
7. // standard output command in Java
8. System.out.println("This message will be displayed on standard output. On the monitor.");
9. }
10.}
1.#include <stdio.h>
2.int main() {
3. // standard input command in C
4. int value;
5. scanf("%d",&value);
6. // standard output command in C
7. printf("This message will be displayed on standard output. On the monitor.");
8.}
1.#include <iostream>
2.int main() {
3. // standard input command in C++
4. int value;
5. std::cin >> value;
6. // standard output command in C++
7. std::cout << "This message will be displayed on standard output. On the monitor.";
8.}
1.using System;
2.class Program {
3. static void Main(string[] args) {
4. // standard input command in C#
5. int value = Convert.ToInt32(Console.ReadLine());
6. // standard output command in C#
7. Console.WriteLine("This message will be displayed on standard output. On the monitor.");
8. }
9.}
1.# standard input command in Python
2.value = input()
3.# standard output command in Python
4.print('This message will be displayed on standard output. On the monitor.')

This is, of course, the simplest and easiest way to start in the universe of programming.

But this is only the beginning! Continue your journey in learning programming. Take the next step and read our article about variables.

autor

David Santiago

Master in Systems and Computing. Graduated in Information Systems. Professor of Programming Language, Algorithms, Data Structures and Development of Digital Games.

Other articles