Sunday, January 30, 2022

Basic Input Function – scanf in C programming (Class 10 Computer notes)

SCANF():

The scanf function is used to get input from the user. The input is stored in a variable in a specified format.

Syntax:

The syntax of scanf function is as follows

scanf (format string, &variable1, &variable2, &variable3);

 Format String: The format string is given in double quotes It may consist of different format Specifiers that indicate the format according to which values will be entered.

Variables:  The variables are used to store the value entered by the user through the keyboard. Each variable refers to a memory location. The symbol & indicates the memory location of the variable in which the input is stored It is called the address operator Getting Single Input.

Examples:

Getting single input:

scanf (“%d”, &a);

The above statement is used to get integers input. The value entered by the user will be stored in variable “a”.



Getting Multiple input:

Scanf function can be used to input many values at the same time as follows;

scanf(“%d %d ,&a, &b);

The above statement will get two inputs in a and b respectively. It is also possible to get different types of input in the same function as follows

scanf (“%d %f”, &a, &b);

The scanf function is normally used in combination with printf function. The purpose of using printf function before scanf is to tell the user that the computer is waiting for input.

Example:

printf(“ Enter your marks”);

scanf(“%d” ,&a);



No comments:

Post a Comment

Which Field to Choose after Inter

انٹرمیڈیٹ_کے_طلباء_و_طالبات_متوجہ_ہوں۔... یہ پوسٹ آپ کے مستقبل سے متعلق ہے۔ عام طور پر میڈیکل کے طلبہ سمجھتے ہیں کہ میڈیکل میں ایم بی بی ایس...