decimal integer : %d Example using printf and scanf function
C Programming Language / Overview of C Language
844Program:
#include int main() { int a = 0; scanf("%d", &a); // input is 45 printf("%d\n", a); return 0; }
Output:
45 45 Press any key to continue . . .
Explanation:
scanf(char *format, arg1, arg2, …)
This function take input using standard input (keyboard) and store it in variable accordingly. It returns the number of items successfully read. Formal parameter arg1, agr2, .. must be a pointer
The given code is a C program that reads an integer from the user using the scanf()
function and prints it to the console using the printf()
function.
Here's how it works:
- The
#include <stdio.h>
line includes the standard input/output library in the program. - The
main()
function is the entry point of the program. - An integer variable
a
is declared and initialized with the value 0. - The
scanf()
function is used to read an integer input from the user and store it in the variablea
. The%d
format specifier is used to indicate that an integer input is expected. - The
&
symbol beforea
in thescanf()
function is used to pass the address ofa
as an argument. This is necessary becausescanf()
needs to modify the value ofa
. - The
printf()
function is used to print the value ofa
to the console using the%d
format specifier. - The
\n
character is used to insert a newline after the output is printed. - Finally, the
return 0;
statement terminates the program and returns 0 to the operating system indicating that the program executed successfully.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.
# C Tutorials
# JAVA Tutorials
# HTML Tutorials
# Computer Fundamental
# Data Structure
# DBMS Tutorials
SQL
# C# Language
# R Language
# PHP
# Python
# Vue JS