Scanln function can be used to take the input from the user in the Golang. Below is the example of taking input from the user:
Now save this file and execute as shown in the below screenshot:
Description About the Program:
- main Package: When we build reusable pieces of code, we will develop a package as a shared library. But when we develop an executable program, we will use the package “main” for making the package as an executable program. The package “main” tells the Golang compiler that the package should compile as an executable program instead of a shared library. The main function in the package “main” will be the entry point of our executable program. Remember when we build shared libraries, we will not have any main package and main function in the package.
- fmt.Println is the print function which is used to print the output in the next line. While fmt.Print is used to display output in the same line. Whatever needs to be printed has to be written in inverted commas ” “.
- var first string is the declaration of the variable first which is of string type. To declare variables following syntax needs to be followed:
var var_name data_type
- fmt.Scanln(&first) is used to take input from user in the next line. While fmt.Scan is used to take input from user in the same line. Ampersand is necessary to give the reference as to in which variable we have to store the variable.
- The Last line will simply add the two string of First Name and Last Name and will output the Full Name.
- How to validate and sanitize user input with PHP?
- Taking Input from User in R Programming
- How to take user input for two dimensional (2D) array in PHP ?
- Take Matrix input from user in Python
- CSS | User Interface
- How to get user location in Android
- How to Create a New User in Windows 10?
- Add a User in Linux using Python Script
- How to read a Matrix from user in Java?
- HTTP headers | User-Agent
- How to hide a div when the user clicks outside of it using jQuery?
- How to display logged in user information in PHP ?
- Deleting a User in Linux using Python Script
- How to create a user defined javap tool?
- Change Image Dynamically when User Scrolls Down | Set 2
- How to create an unordered_map of user defined class in C++?
- How to create an unordered_set of user defined class or struct in C++?
- How to display popup message when logged out user try to vote ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.