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; } |
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.
Contact Us