Unions

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.91
List Price:  €120.29
You save:  €34.37
£74.62
List Price:  £104.47
You save:  £29.85
CA$137.73
List Price:  CA$192.84
You save:  CA$55.10
A$153.57
List Price:  A$215
You save:  A$61.43
S$128.82
List Price:  S$180.36
You save:  S$51.53
HK$780.45
List Price:  HK$1,092.67
You save:  HK$312.21
CHF 80.49
List Price:  CHF 112.69
You save:  CHF 32.20
NOK kr1,000.46
List Price:  NOK kr1,400.69
You save:  NOK kr400.22
DKK kr641.23
List Price:  DKK kr897.75
You save:  DKK kr256.51
NZ$170.72
List Price:  NZ$239.01
You save:  NZ$68.29
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,175.01
List Price:  ৳17,045.50
You save:  ৳4,870.49
₹8,813.10
List Price:  ₹12,338.70
You save:  ₹3,525.59
RM423.25
List Price:  RM592.57
You save:  RM169.32
₦153,210.67
List Price:  ₦214,501.07
You save:  ₦61,290.40
₨28,383.20
List Price:  ₨39,737.62
You save:  ₨11,354.41
฿3,239.07
List Price:  ฿4,534.83
You save:  ฿1,295.76
₺4,114.87
List Price:  ₺5,760.99
You save:  ₺1,646.11
B$544.45
List Price:  B$762.25
You save:  B$217.80
R1,772.09
List Price:  R2,481
You save:  R708.90
Лв167.53
List Price:  Лв234.55
You save:  Лв67.01
₩139,447.22
List Price:  ₩195,231.68
You save:  ₩55,784.46
₪339.07
List Price:  ₪474.71
You save:  ₪135.64
₱5,746.67
List Price:  ₱8,045.57
You save:  ₱2,298.90
¥14,854.89
List Price:  ¥20,797.44
You save:  ¥5,942.55
MX$1,875.93
List Price:  MX$2,626.38
You save:  MX$750.44
QR365.13
List Price:  QR511.19
You save:  QR146.06
P1,436.54
List Price:  P2,011.22
You save:  P574.67
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£4,849.46
List Price:  E£6,789.44
You save:  E£1,939.98
ብር14,206.62
List Price:  ብር19,889.84
You save:  ብር5,683.21
Kz91,186.39
List Price:  Kz127,664.59
You save:  Kz36,478.20
CLP$96,808.31
List Price:  CLP$135,535.51
You save:  CLP$38,727.20
CN¥713
List Price:  CN¥998.24
You save:  CN¥285.23
RD$6,292.09
List Price:  RD$8,809.17
You save:  RD$2,517.08
DA12,984.71
List Price:  DA18,179.12
You save:  DA5,194.40
FJ$226.17
List Price:  FJ$316.65
You save:  FJ$90.48
Q767.42
List Price:  Q1,074.42
You save:  Q307
GY$20,938.25
List Price:  GY$29,314.40
You save:  GY$8,376.14
ISK kr12,336.76
List Price:  ISK kr17,271.96
You save:  ISK kr4,935.20
DH900.12
List Price:  DH1,260.21
You save:  DH360.08
L1,661.93
List Price:  L2,326.78
You save:  L664.84
ден5,257.29
List Price:  ден7,360.41
You save:  ден2,103.12
MOP$804.11
List Price:  MOP$1,125.79
You save:  MOP$321.67
N$1,759.85
List Price:  N$2,463.86
You save:  N$704.01
C$3,684.68
List Price:  C$5,158.70
You save:  C$1,474.01
रु14,123.84
List Price:  रु19,773.94
You save:  रु5,650.10
S/353.62
List Price:  S/495.09
You save:  S/141.46
K423.91
List Price:  K593.49
You save:  K169.58
SAR375.19
List Price:  SAR525.28
You save:  SAR150.09
ZK2,365.54
List Price:  ZK3,311.85
You save:  ZK946.31
L436.41
List Price:  L611
You save:  L174.58
Kč2,103.13
List Price:  Kč2,944.47
You save:  Kč841.33
Ft34,037.82
List Price:  Ft47,654.32
You save:  Ft13,616.49
SEK kr945.38
List Price:  SEK kr1,323.57
You save:  SEK kr378.19
ARS$137,659.46
List Price:  ARS$192,728.75
You save:  ARS$55,069.29
Bs691.82
List Price:  Bs968.58
You save:  Bs276.75
COP$404,511.35
List Price:  COP$566,332.08
You save:  COP$161,820.72
₡50,618.68
List Price:  ₡70,868.18
You save:  ₡20,249.49
L2,621.40
List Price:  L3,670.07
You save:  L1,048.66
₲723,189.07
List Price:  ₲1,012,493.63
You save:  ₲289,304.56
$U4,001.03
List Price:  $U5,601.60
You save:  $U1,600.57
zł366.60
List Price:  zł513.26
You save:  zł146.65
Already have an account? Log In

Transcript

Hello, and welcome to the 44th tutorial on c++ programming series. And in this part we're going to be looking at unions. Unions allow a single area memory to be accessed by multiple data types, but not at the same time. This is useful if you know a group of variables will never be in use together. So storing them in a single area memory is okay, as long as one would override the obey if you were to assign a value to one that would override what you have in memory. So any the previous variable that was being stored there will no longer technically exist.

So let's just show you how to implement unions. The syntax of unions are very similar to struct which we have covered recently, but it's functionally is obviously totally different. So we do use the keyword Union for love about programming, especially c++ didn't Name of what you're doing has obviously a keyword and the keyword is that name. And it sounds pretty obvious but you'll get stuff where it's doesn't really follow any sort of decent convention. Okay, so now you just put the name of your union one's got a number, input curly braces, semicolon at the end here. That is okay.

You basically put all your variables on put into coin, double body. Boom, hello. And now what we're going to do is create an instance of the number union so number one I'm creating an instance called number w sciatic sees a lowercase n current building number dot i equals seven and if we do STD c out no matter I know, you are STD. And long running actuate the console runner and we get the value seven. But if we were to just sorry about that. And if we were to just literally copy and paste this, but we can change this to a tee and it might, it can alter the deal D. And it's going to change this to 6.7.

And that's when we get my product global or because the variable exists now so but if you were to put data in and run it, you can get the value 6.7 and they'll be the same with the Boolean variable Hello. So you can only store one value at any given time, but it's useful. Like I said, if you know that there's a group of variables and none of them will ever be in existence when one of one or more of the other variables is in it. is in existence or in use, then it's great we help to save memory to the only using one area of memory. So that's it for this part we looked at Union the very simple in the next part of this series we'll be looking at enumerators if you have any questions feel free to message us our support systems clearly okay.

Email will be in the description you can comment on these videos directly messages via YouTube. All the required links or source code will also be in the description. And as usual, thanks for watching and I hope you have a nice day.

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.