# Thread: tell me the function of scanf();

1. ## tell me the function of scanf();

what is scanf function
can someone help me to explain it?

2. scanf() is made to take input from the user. To give a simple example:

Code:
```int a = 0;
printf("Enter an integer: ");
scanf("%d", &a);```
This short example declares an integer a, asks the user to enter an integer and waits until an integer is entered.

Let's dissect the scanf(): it has two parts, separated by a comma:

"%d": means that the input has to be interpreted as an integer. This is called a conversion character. You can also take "%c" which interpretes the input as a character ('a' or '#', or whatever). With "%s" you can input a whole string.

&a: means that the value that was entered should be stored in the variable a. The & means "the address of". In this example we put the value in the address where a is pointing to. If this sounds like magic, read first about pointers and addresses.

To summarize:

scanf("%d", &a); takes an integer and puts it in the address of a.
I hope you're a bit wiser now...

3. Originally Posted by hilarius
scanf() is made to take input from the user. To give a simple example:

Code:
```int a = 0;
printf("Enter an integer: ");
scanf("%d", &a);```
This short example declares an integer a, asks the user to enter an integer and waits until an integer is entered.

Let's dissect the scanf(): it has two parts, separated by a comma:

"%d": means that the input has to be interpreted as an integer. This is called a conversion character. You can also take "%c" which interpretes the input as a character ('a' or '#', or whatever). With "%s" you can input a whole string.

&a: means that the value that was entered should be stored in the variable a. The & means "the address of". In this example we put the value in the address where a is pointing to. If this sounds like magic, read first about pointers and addresses.

To summarize:

scanf("%d", &a); takes an integer and puts it in the address of a.
I hope you're a bit wiser now...
thx bro

4. Get familiar with unix/linux (especially man pages) or type in man scanf and see what you get.