Basic Input and Output

The basic input and output in C are done using two <stdio.h> functions namely scanf() and print() respectively.

Basic Output – print()

The printf() function is used to print the output on the standard output device which is generally the display screen.

Syntax of printf()

printf("formatted-string", ...{arguments-list});

where,

  • formatted-string: String to be printed. It may contain format specifiers, escape sequences, etc.
  • arguments-list: It is the list of data to be printed.

Basic Input – scanf()

The scanf() function is used to take input from the standard input device such as the keyboard.

Syntax of scanf()

scanf("formatted-string", {address-argument-list});

where,

  • formatted-string: String that describes the format of the input.
  • address-of-arguments-list: It is the address list of the variables where we want to store the input.

Example of Input and Output

C




// C program to illustrate the basic input and output using
// printf() and scanf()
#include <stdio.h>
  
int main()
{
    int roll_num;
    char name[50];
  
    // taking input using scanf
    scanf("Enter Roll No.: %d", &roll_num);
    scanf("Enter Name: %s", name);
  
    // printing output using printf
    printf("Name is %s and Roll Number is %d", name,
           roll_num);
  
    return 0;
}


Output

Name is  and Roll Number is 0

Input

Enter Roll No: 20
Enter Name: w3wiki

Output

Name is w3wiki and Roll Number is 20.

C Cheat Sheet

This C Cheat Sheet provides an overview of both basic and advanced concepts of the C language. Whether you’re a beginner or an experienced programmer, this cheat sheet will help you revise and quickly go through the core principles of the C language.

In this Cheat Sheet, we will delve into the basics of the C language, exploring its fundamental concepts that lay the groundwork for programming. We will cover topics such as variables, data types, and operators, providing you with a solid understanding of the building blocks of C programming.

Similar Reads

Basic Syntax

Consider the below Hello World program:...

Variables

...

Data Types

A variable is the name given to the memory location that stores some data....

Identifiers

The data type is the type of data that a given variable can store. Different data types have different sizes. There are 3 types of data types in C:...

Keywords

Identifiers is the name given to the variables, functions, structure, etc. Identifiers should follow the following set of rules:...

Basic Input and Output

Keywords are the reserved words that have predefined meanings in the C compiler. They cannot be used as identifiers....

Format Specifiers

The basic input and output in C are done using two functions namely scanf() and print() respectively....

Escape Sequence

...

Operators

Format specifiers are used to describe the format of input and output in formatted string. It is different for different data types. It always starts with %...

Conditional Statements

Escape sequences are the characters that are used to represent those characters that cannot by represented normally. They start with ( \ ) backslash and can be used inside string literals....

Loops

Operators are the symbols that are used to perform some kind of operation. Operators can be classified based on the type of operation they perform....

Jump Statements

Conditional statements are used to execute some block of code based on whether the given condition is true. There are the following conditional statements in C:...

Example of Loops and Jump Statements

...

Arrays

Loops are the control statements that are used to repeat some block of code till the specified condition is false. There are 3 loops in C:...

Strings

Jump statements are used to override the normal control flow of the program. There are 3 jump statements in C:...

Pointers

C // C program to illustrate loops #include    // Driver code int main() {     int i = 0;        // for loop with continue     for (i = 1; i <= 10; i++) {         if (i == 5 || i == 7) {             continue;         }         printf("%d ", i);     }     printf("\n");        // while loop with break     i = 1;     while (i <= 10) {         if (i == 7) {             break;         }         printf("%d ", i++);     }     printf("\n");        // do_while loop     i = 1;     do {         printf("%d ", i++);     } while (i <= 10);     printf("\n");        // goto statement     i = 1; any_label:     printf("%d ", i++);     if (i <= 10) {         goto any_label;     }        return 0; }...

Functions

...

Structures

An array is a fixed-size homogeneous collection of items stored at a contiguous memory location. It can contain elements from type int, char, float, structure, etc. to even other arrays....

Union

...

Enumeration (enum)

Strings are the sequence of characters terminated by a ‘\0’ NULL character. It is stored as the array of characters in C....

File Handling

...

Preprocessor Directives

Pointers are the variables that store the address of another variable. They can point to any data type in C...

Common Library Functions

...

Conclusion

...