c programming scanf

Hey am Junaid. Today I will explain you about the c programming scanf function. As I have already written on c programming print function. This function is used to take input from the end user of the program. By using c programming scanf function you can get any kind of input from user. Like if any you want to take age details or name details you can get through scan function.

C Programming Scanf function

Before knowing any function you must have to know the right use of that function. Such as you have to create a program, which asked the user to enter the age. So here we used the scanf to get the input from user into the program. I have coded this example below you can check this.

Such as if you have to create the program which asked the user to enter the name. So for this purpose we will also used the scanf function to get input from the user. I have also created the code below.

The Basic Syntax

C programming scanf function basic syntax is similar to printf function. You just need to replace the printf keyword with scanf function. Like the code below.

Now you are familiar with the syntax if scan function. The next thing is to understand the concept of scan function. As I have already given some examples in the start of post. Now I just recall them to understand their logics. Let’s consider the problem number one, in which we have to take the age from the end user. First we took the variable in which we store the value given by the user. Then in scanf we will tell the compiler to store keyboard or input source interruption. Like you can see in the code.

In this I have given the command to compiler that, the variable age is type of integer and you have to store only integer value in the age variable.

Now checked the second problem which is to take the name of user. As you saw the code in which I have taken the variable. The name and datatype is character along with the type array. You don’t need to be confused with this. We will discuss it too in next articles. You have to just understand the concept. That how you can used scanf in alternative ways. Now again I have given the instruction to the compiler. That you have to store the interrupt of input. Which is only character type like name of anyone and stored it In variable. Which we have declared as ‘name’.


The first word is the keyword of function which is used for taking input.

Then parenthesis are come.

Inside parenthesis you have to give the address specifier according to datatype, enclosed in double quotes.

Then after double quotes you have to give comma and used “&” ampresend along with variable in which you have to store the inputs.

After this you have to put semicolon (;) at the end to tell compiler, I am ending this function here. That’s all.


Final words

I have tried my best to deliver the concept of c programming scanf function. I have also included the reference codes and video tutorial on this topic. You can try the codes on your own compiler. If you are facing any kind of error in c programming scanf function you can contact me through the comments and Facebook Group. I hope this is very help full for you. Please share this with your mates and practice a lot to get the idea for the alternative use.


CommentLuv badge