printf and scanf functions tutorial in c-[C programming tutorial for beginners 2021]

 

 C INPUT AND OUTPUT FUNCTIONS

Today we will learn about input and output functions in c, we use scanf() for taking an input from the user and use printf() function to print the output on the screen. The standard library stdio.h contains the input and output functions printf() and scanf().


printf and scanf functions tutorial in c
printf and scanf functions tutorial in c


The syntax of scanf:-

scanf("format specifier", &argument_list);  

The scanf() function is written with the keyword scanf followed by parenthetis and the format specifier within the quotes and then comma and then the argument list with address of operator.

The syntax of printf:-

printf("format specifier", argument_list);  

The printf() function is written with the keyword printf followed by parenthetis and the format specifier within the quotes and then comma and then the argument list.

Format Specifier:-

The format specifier is used to tell the compiler which data type is used like (int, float ..) %d, %f ..etc.

Source code:-


#include <stdio.h>
#include <stdlib.h>

int main()
{
    //int var;
    //float number;

    //printf("Hello world");
    //printf("\nWelcome to learncodingmars Youtube channel");

    //int var;
    //printf("Enter a number: ");
    //scanf("%d", &var);
    //printf("The number entered is %d", var);


    //float a = 6.6;
    //printf("the value is: %f", a);

    //printf("\nEnter a decimal value to be displayed on the screen: ");
    //scanf("%f", &a);

    //printf("The value is: %f", a);

    int b;
    printf("Enter no.: ");
    scanf("%d", &b);
    printf("The value is: %d", b);

    return 0;
}
Learn more about printf and scanf in c.

Post a Comment

0 Comments