User Input/Output

We already know how to produce values in C using the printf() function. To obtain user input, another method known as scanf() is used.Two arguments are required by the scanf() method.The variable’s format specifier (as shown in the example below) the memory address of the variable is stored by the reference operator (&myNum). The input data is sent to this.

Input refers to the act of providing data to a software. A file or the command line can be used to provide an input. The built-in functions in C programming make it possible to read the input and pass it along to the programme as needed.

The term “output” refers to the presentation of data in a file, on the screen, or on a printer. A collection of built-in functions for C programming are available to output data to the computer screen as well as save it to text or binary files.

One such illustration shows how a programme receives user input.

{
    int marks;
    char name[30];
    printf("Enter student's name: ");
    scanf("%s", name);
    printf("Enter marks in Maths: ");
    scanf("%d", &marks);
    printf("Hello %s! You have scored %d in Maths!", name, marks);
    return 0;
}

Enter student’s name: Rohan

Enter marks in Maths: 98

Output: Hello Rohan! You have scored 98 in Maths!

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in