Declaration and initialization

GetGoing: Introduction to Golang Data types and control structure
2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
This is a free item
$0.00
د.إ0.00
Kz0.00
ARS$0.00
A$0.00
৳0.00
Лв0.00
Bs0.00
B$0.00
P0.00
CA$0.00
CHF 0.00
CLP$0.00
CN¥0.00
COP$0.00
₡0.00
Kč0.00
DKK kr0.00
RD$0.00
DA0.00
E£0.00
ብር0.00
€0.00
FJ$0.00
£0.00
Q0.00
GY$0.00
HK$0.00
L0.00
Ft0.00
₪0.00
₹0.00
ISK kr0.00
¥0.00
KSh0.00
₩0.00
DH0.00
L0.00
ден0.00
MOP$0.00
MX$0.00
RM0.00
N$0.00
₦0.00
C$0.00
NOK kr0.00
रु0.00
NZ$0.00
S/0.00
K0.00
₱0.00
₨0.00
zł0.00
₲0.00
L0.00
QR0.00
SAR0.00
SEK kr0.00
S$0.00
฿0.00
₺0.00
$U0.00
R0.00
ZK0.00
Already have an account? Log In

Transcript

Hi, in this video, we're going to be talking about the go data types. So go as mainly three types of data types, atomic, unsafe and abstract data types. So atomic data types are almost in every languages, string integers, 32 bit integers, 64 bit unsigned integers, unsigned 64, and 32 bit integers, then we've got unsafe, yes, golang supports pointers. So call by value and call by reference are still a thing in. And then we have abstract data types. So in this video, we're going to be talking about the atomic data types.

So to declare a variable, simply do that in one and then you can do m one is equal to two and simply print out this m one variable. To run this logic simply to go run main.go. And there you have it, to print. To declare multiple variables, what you can do is you can do this and one is equal to two and two is equal to three And you're going to notice that in this case, we don't need to define end or in 64, or in 32. That is because we used the equality sign. So it means that it's automatically implicit.

So, if we do this, if you do aware, and one in 32, and we do a wire into int 64, let's see what happens. Arrow, obviously, because we can't add items of two different data types. So what we can do in this case is we can type costed, so by type costing, by type costing, we can convert one data type into another data type. So how we might do that is like this. So simply do int 64 of m one. So we converted our 32 bit and 32 bit integer m one into 64 bit integer and now we got the answer.

And the answer was zero because by default, all of the variables in golang are initialized as 01. More interesting thing about it is, rather than declaring variables, you can also initialize variables in just one line. So you declare variables like this. But for initializing variables, you simply need to do m one is equal to two and two is equal to three. And we can simply remove this in 64 line. And let's see if it works or not.

Yes, it will. So this was our video on integers. And we also have untie unsigned integer types, which are very useful if you want counters and all of that. In the next video, we'll be talking about strings

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.