CodesandTutorials
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.
You are here - Home > Programming > C > Basics

Scanf


Description

Scanf stands for "scan formatted" is an built-in function defined in stdio.h header file that scans the input entered by the user and stores into the variable specified.

Syntax

  • Scanf("format specifiers", arguments);

Similar to printf, scanf format specifiers argument determines how many arguments are there and are of what data types. Argument is the list of variable names starting with '&' sign and separated by commas.

Eg: scanf("%d%d", &a,&b);

In the above example it scans two variables of integer data types and stores the value into a and b variable. Where &a and &b are the pointers pointing to the memory location to store the value, if pointers are not declared it will store the value in wrong memory location as compiler doesn't detects the error at compile time.

The input value of two variables must be standard input entered by separating blank space or by entering on a new line by the user.


Tip Box

scanf, sscanf & fscanf

scanf reads from the standard input stream stdin.

sscanf reads character string from specified string parameter.

fscanf reads data from the file named input stream.


Advertisement





Terms of Use | Privacy Policy | Contact Us | Advertise
CodesandTutorials © 2014 All Rights Reserved