Now when we have learnt how to print the basic text at the screen, some people might have thought that why would we always need to write something on the screen while we are coding our program, so the answer is that, the printf is basically a printing command, in order to take input from user we would use scanf, that takes input from user and transfer it to the processing machine.
Scanf can take input in the form of characters1, integers2, float3 etc. These three are some of the data types of C language, remaining data types would be cleared in further articles. By using scanf you can take information from user, it can ask questions from the user like, if someone is student we can make a form that asks his/her name, class, roll number, total marks and obtained marks. For this we would need English alphabets for name, class, total marks and obtained marks would be numbers and class roll number would be alphanumeric4(Alpha numeric means the characters comprising of alphabets as well as numbers).
The syntax used for scanf is simple and just like printf (learnt in lesson-3), the difference that creates sense is the symbol of Ampersand (&), that refers to some address. The information or data that we enter is saved at some place in memory and this sign refers to that address. For taking an input from user, we first have to make room for that storage; this room may be of an integer, character or float type. We would start from the integer is it would be easy to understand and making the firm basis.
Continue reading →