Suppose you want to store the 10 numbers. The one choice is to create a 10 different variable but it is difficult when number of variable are increases. So the next solution that is more feasible is array. An array is the collection of various similar type elements stored in contiguous memory locations. All the array elements share the common name. To uniquely identify each element an index or subscript is associated with the element. so the array is also known as subscript variable . In the given figure arrangement of array elements are shown. The address of the first element is 100. If the given array is of type integer and integer occupies 2 bytes then the next element in the array has address 102,104 etc as given in the figure. How to access array elements using subscript operator it is also shown in the given figure. Array index always start with 0. To access array element subscript operator is used.[] is called subscript operator.a[0] read a of 0 or 0th element of a C...
What is Element? An element is the combination of opening tag, closing tag and text between the opening and closing tag. The following figure helps you to understand, what is an element? Element in Html Types of Element in HTML Block level elements Inline elements Block level Element Block Level elements are those which always starts from a new line. Examples of block level elements All Headings (h1, h2, h3, h4, h5, h6) Paragraphs Lists Inline Element Inline elements are those, which don’t change the line automatically. Examples of inline element Bold (<b>Bold</b>) Italic (<i>Italic</i>) Underline (<i>Underline</i>) Links (<a>Links</a>) Watch the video
Rules for Creating the variable name Variable name can contain Alphabets (A-Z/a-z), Digits (0-9) and Underscore( _ ). A variable name must start with alphabet or underscore. Spaces and special systems are not allowed. Reserved words are not allowed as a variable name. A variable name should be meaningful. Go is case sensitive language so age, Age, AGE all are treated as a different variable. Some correct variable names name father_name fatherName __AGE number1 car_modal_name is_verified intnum Some incorrect variable names father's_name father#name 2persons 0007 000Name int a#b Note There are two popular ways to create multi-word variables. player_name: Each word is separated by an underscore playerName: camel case, the first word is in small and from second word first letter of each word is capitalized. Variable Scope Scope is the range of places where a variable is allowed to be used is called variable scope.Variable Scope can ...
What is variable Variable is an entity which can change during the problem. For example: y = x + 5 x y 1 6 2 7 3 8 As shown in the above example, as the value of x is changing y gets changed. so in the above expression x and y are variable and 5 is a constant. In programming whenever you create a variable, a memory is reserved and a name is assigned to it. If initialized with value then binary value of that will gets stored in memory otherwise initialized with default value. Following figure shows the memory map of a variable. Creating a variable var name string = "Hello Go" In the above example, a variable is created labeled with the name of type string and initialized with value "Hello Go" . the var keyword is used to create a variable. var name = "Hello Go" In the above code snippet, the only difference is that data type is not given, because when you initialize the variable then ...
What is identifier. A Name in Java program is called identifier, which can be used for identification purpose. It can be a class name, interface name, method name, label name, variable name etc. Example In the above example words marked with red underline are identifiers. As you can see there are 5 identifiers Test (Class Name) main (Method Name) String (Pre-defined Class Name) args (Variable Name) println(Method Name) Rules / Convention for Identifier Naming While defining Java identifier name, we have to follow some rules as listed below. Allowed characters in Java identifier are listed below. A to Z (Uppercase letters) a to z (Lowercase letters) 0 to 9 (Digits) _ (Underscore) $ (Dollar sign) Example: contact_number ( ✓ ) contact# (✕) Identifier can't starts with digit. Example abc123 ( ✓ ) 123abc (✕) Java is a case sensitive language all variable listed below are different, but it is not a good pr...
Strings are sequence of characters with definite length and can be created by enclosing in double quotes "Hello Go" and back ticks `Hello Go`. A string is a sequence of characters. Strings are the collection of individual bytes, where each character occupy single byte. Characters out of the ASCII characters (can say characters from other languages) occupy more than one byte. A string can be created by enclosing in double quotes "Hello Go" or backticks `Hello Go`. The difference between double quotes and backticks is that double quotes allow escape sequences like \n (newline) and \t (tab) and parses them but backticks don't. Example-1: package main import "fmt" func main( ) { fmt.Println(len("Hello Go")) fmt.Println("Hello Go"[1]) fmt.Println("Hello"+" "+"Go") } Output: 8 101 Hello Go Output Explained: fmt.Println(len("Hello Go")) ...
package main import "fmt" func main() { var name string = "Mahesh" age := 25 price := 300.40 fmt.Printf("%T %v\n",name,name) fmt.Printf("%T %v\n",age,age) fmt.Printf("%T %v\n",price,price) } Output string Mahesh int 25 float64 300.4 Explanation In the above program snippet, we use Printf() function of fmt package to print the formatted output. Withing the Printf( ) %T and %v is called format specifier which represents the output format. %T represents the Type, which prints the variable type %v represents the variable's value. age := 25 , creates a variable age with the short variable declaration and assign the value 25. In this case, the variable automatically receives the type and here age is the type of int. price:=300.40, In this statement price, is created of type float64 because float64 is the default type of floating values in go lang. To create a float32 ty...
Introduction to decision making Sometimes we need to introduce a power in our program, that our program should automatically make the decision. For example: if the temperature of the day is more than 20 degree then it's hot otherwise it's cool. To introduce this kind of power in our program, we use decision making statements as the list below... if-else statements nested if-else statements else-if ladder switch/case-control statement Let's create a program to check whether a number is even or odd. Program to check a number is even or odd in Go lang. package main import "fmt" func main() { var n int32 fmt.Print("Enter any number:") fmt.Scan(&n) if n % 2 == 0 { fmt.Println(n,"is even") } else { fmt.Println(n,"is odd") } } Output: Enter any number:55 55 is odd Explanation: A number is even if it is divisible by 2 otherwise odd. So to che...
On Windows Download the latest version of go MSI installer from https://golang.org/dl/ best suited for your system architecture. Start the installation by double-clicking on the installer and installer wizard will open as given in the following figure. For the installation follow the wizard instructions. Note that when you installing go lang using installer then it will ask the location where go will be installed as shown in the figure below. Installation directory of go lang is called GOROOT here the GOROOT is c:\go directory. After this follow the wizard instructions and complete the go lang installation. Test Go installation To Check that Go is installed correctly or not, you need to create a go workspace (a place /folder/directory in which you save you go programs) and create a sample go program and run the program using the command line. The sample program is given below... You can create a sample program by using any simple text editor like n...
Constant in go lang Constants are basically variable which value can't change once created. Constants are created in the same way as variables, the only difference is that to create a variable use var keyword and to create constant use const keyword. Constant Example-1 package main import "fmt" func main() { const playerName string = "Rahul" fmt.Println(playerName) //playerName = "Micky" //compile time error, cannot assign to playerName. } Constant Example-2 package main import "fmt" func main() { const METER_PER_FEET = 0.3048 var feet,meter float32 fmt.Print("Enter value in feet...") fmt.Scan(&feet) meter = feet * METER_PER_FEET fmt.Printf("Meter %.2f",meter) } Note: In the above example, METER_PER_FEET is a constant. It is suggested that constant name should be written in uppercase, each word separated by an unders...
Comments