Below is syntax of Scanf. It requires two arguments:
scanf("Format Specifier", Variable Address); Format Specifier: Type of value to expect while input Variable Address: &variable returns the variable's memory address.
In case of a string (character array), the variable itself points to the first element of the array in question. Thus, there is no need to use the ‘&’ operator to pass the address.
(Is Base address = address of first element)? 1
- ‘&’ is used to get the address of the variable. C does not have a string type, String is just an array of characters and an array variable stores the address of the first index location.
- By default the variable itself points to the base address and therefore to access base address of string, there is no need of adding an extra ‘&’
This article is contributed by Ajeet. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Problem with scanf() when there is fgets()/gets()/scanf() after it
- Why to use fgets() over scanf() in C?
- Use of & in scanf() but not in printf()
- Return values of printf() and scanf() in C/C++
- Cin-Cout vs Scanf-Printf
- scanf() and fscanf() in C - Simple Yet Poweful
- Inbuilt library functions for user Input | scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s
- Difference between scanf() and gets() in C
- scanf("%[^\n]s", str) Vs gets(str) in C with Examples
- Commonly used String functions in C/C++ with Examples
- What are the C programming concepts used as Data Structures
- Why variable name does not start with numbers in C ?
- Why only subtraction of addresses allowed and not division/addition/multiplication
- Why does sizeof(x++) not increment x in C?
- Why strcpy and strncpy are not safe to use?
- Why is the size of an empty class not zero in C++?
- Why C treats array parameters as pointers?
- Why copy constructor argument should be const in C++?
- Why is a[i] == i[a] in C/C++ arrays?
- Why is C considered faster than other languages ?