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")) ...
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...
Literals in Java int a = 5; In the above expression, a is a variable but 5 is literal. Literal can be of many types, we will discuss all types of literal one by one. Integral Literal Any integer constant is treated as integral literal. it can be written in 3 formats. int a = 10; (decimal format) int a = 010; (octal format, equivalent to 8) int a = 0x10; (hexadecimal format, equivalent to 16) Note: Octal constants can contain digits from 0 to 9. Hexadecimal constants can contains digits from 0 to 9 and a to f, where a to f can be uppercase or lowercase. Example - 1: int a = 10; ( ✓ ) int a = 0678; (✕) // Compile time error, number too large int a = 0777; ( ✓ ) int a = 0xace; ( ✓ ) int a = 0xBeer; (✕) // Compile time error, number too large Example - 2: int a; a = 10 + 010 + 0x10; System.out.println(a); // 34, because 010 = 8 and 0x10 = 16 so 10 + 8 + 16 Important Notes We(pr...
Pointer is called the soul of c. The importance of pointer can be understood by the fact that most of the device driver or embedded system program are created in c. Pointer makes the c most usable and flexible programming. Due to the availability of the pointer, it is possible to write a program such as a device driver. These programs are also known as the device driver. To understand the pointer we have to first understand the memory organization of any variable. The following figure shows the fact. Whenever a variable stored in memory it occupies some memory space and every memory space has a unique number associated with it known as an address. Every byte in member has a different address. If we create an integer variable and suppose it occupy 2 bytes in memory, then two addresses are associated with it but its first address is enough to access it. so the address of next bytes is less useful. To access the address of a variable & (Address of) operator is used. To understa...
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
What is Reserved Words. In every language some words are already reserved to represent some action or meaning. For example in English some reserve words are listed below. Apple Run Cat Dog Eat Similarly in Java there are some words which meaning is already reserved, such words are called reserved words / keywords. In Java, Only 53 words are reserved words. Difference between Keywords and Reserved Literals If reserve words represents some functionality, then called Keywords . If reserve words represents some value, the called Reserve Literals . Reserve Literals (3) true (boolean value) false (boolean value) null (Object reference value) Keywords (50) Used Keywords (48) Unused Keyword (2) Goto Const All 53 Reserved Words List Data types (8) byte short int long float double boolean char Flow Control (11) if else switch case default while for do break continue return Modifiers (11) public private pr...
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...
Data type defines a set of related values, describe the operations that can be done on them and define the way the stored in memory. For example: Suppose you have a Car of VW Polo, but a car can be of any other company with some other basic and some advanced features. But if we called a name Car, then in your mind a picture is created that there is a vehicle with 4-wheels and steering. Each car has some features like the color, company, make, model etc. Types in programming work in a similar way, For example, "Hello World" is a string and every string have some length. Numbers Go Comes with different types to represent numbers, Numbers can be categorized into two broad categories... Integer The integer represents only those numbers which don't include any decimal places and can be of any positive and negative numbers. Example : {1, 3, -4, 11, 123, 534} all are integer numbers Go's integer type can be uint8, uint16, uint32, uint64, int8, int16, in...
Printing in C In C for printing purpose, We Use A Function Called printf( ) . A function is a small program used to perform a specific task. The function receives some input known as an argument and produces some output called return value. Functions are always suffixed with parenthesis ( ). Syntax of printf( ) printf("Control String",[List or Variable]); Note: Control string is a sequence of characters which you want to print. ([ ]) square brackets around the list or variable represent that it is optimal. Example Of printf( ) printf("hello"); //Print hello int a=5,b=6; printf("a=%d b=%d",a,b); //print the value of a and b. int a=5,b=6; //Varialbe Declaration printf("%d",a+b); //Print 11. Note: In printf( ) expression can be written .The example is given above. The first program, Say Hello World in C programming /*program to print the "Hello world"*/ #include<stdio.h> int main() { printf(...
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 ...
Comments