C programming + scanf

star Reading data From Keyboard

scanf(”control string”, &variable01, &variable02, …);

=> The ampersand symbol, &, is very important. It’s an operator specifying the variable name’s address. Omitting it, might result into unexpected results.

star How Does Scanf Behave During Execution

Consider: scanf(”%d”, &number);

=> This statement halts execution and waits for a value to be entered. That value will be stored in a variable ‘number‘ and is of type ‘integer‘ as specified by the format specifier ‘%d
=> The compiler will proceed once a number is typed in and the ‘Return‘ key is pressed.

star The Code At Work

PROGRAM:

//include your libraries here..
void main()
{
int number;

printf(”Enter an integer: \n”);     //prompt message
scanf(”%d”, &number);                 //read message

printf(”The number you entered is: %d”, number);
}

OUTPUT:

Enter an integer:
25
The number you entered is: 25

That’s it, a very simple program to keep things simple for you to understand how interactivity works. Do use the comment form below to add your part..

bulb Other C Programming Articles:
=> Random Numbers in C programming
=> It’s Too Easy To Make This Simple, But Worse, Logical Error In Programming

Share This Article with your friends if you appreciate my effort to write it!

  Start Learning With Wakish - Enroll Freely Now! (Click Here!)

Share Wakish Wonderz On Facebook
SUBSCRIBE ⇒ ∑ [ EMAILRSS ] wakish.info

Posted in: World Of Programming

Leave a Comment

Close
E-mail It