Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exercise on basic types for the first day #518

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

hageboeck
Copy link
Contributor

@hageboeck hageboeck commented Apr 2, 2024

This is an attempt at deepening the understanding of type promotions and
operators for basic types. This should address most of the ideas in
issue #157.

Fix #157

A typical run of this exercise looks like this:

Using literals of different number types:
Line 17: 5                     type=int                 value=5
Line 18: 5/2                   type=int                 value=2
Line 19: 100/2ull              type=unsigned long long  value=50
Line 20: 2 + 4ull              type=unsigned long long  value=6
Line 21: 2.f + 4ull            type=float               value=6
Line 22: 0u - 1u               type=unsigned int        value=4294967295
Line 23: 1.0000000001f         type=float               value=1
Line 24: 1. + 1.E-18           type=double              value=1

Using increment and decrement operators:
Line 30: b = a++               type=int                 value=1
Line 31: c = ++a               type=int                 value=3
Line 32: a                     type=int                 value=3
Line 33: b                     type=int                 value=1
Line 34: c                     type=int                 value=3

Compound assignment operators:
Line 38: n *= 2                type=int                 value=2
Line 39: n *= 2.9              type=int                 value=5
Line 40: n -= 1.1f             type=int                 value=3
Line 41: n /= 4                type=int                 value=0

Logic expressions:
Line 47: alwaysTrue && condition1 && condition2 type=bool                value=0
Line 48: alwaysTrue || condition1 && condition2 type=bool                value=1
Line 49: alwaysTrue && condition1 || condition2 type=bool                value=1
Line 50: condition1 != condition1 type=bool                value=0
Line 51: condition2 = !condition2 type=bool                value=0
Line 52: alwaysTrue && condition1 && condition2 type=bool                value=0
Line 53: alwaysTrue || condition1 && condition2 type=bool                value=1
Line 54: alwaysTrue && condition1 || condition2 type=bool                value=0

Line 57: false || 0b10         type=bool                value=1
Line 58: false | 0b10          type=int                 value=2
Line 59: 0b1 & 0b10            type=int                 value=0000000000000000
Line 60: 0b1 | 0b10            type=int                 value=0000000000000011
Line 61: 0b1 && 0b10           type=bool                value=0000000000000001
Line 62: 0b1 || 0b10           type=bool                value=0000000000000001

Play with characters and strings:
Line 65: "a"                   type=char [2]            value=a
Line 66: 'a'                   type=char                value=a
Line 72: charArray             type=char [20]           value=@U5??
Line 73: charArray[0] = 'a'    type=char                value=a
Line 74: charArray             type=char [20]           value=aU5??
Line 75: charArray[1] = 98     type=char                value=b
Line 76: charArray             type=char [20]           value=ab5??
Line 77: charPtr               type=char*               value=ab5??

@hageboeck hageboeck self-assigned this Apr 2, 2024
@hageboeck hageboeck force-pushed the basicTypes branch 3 times, most recently from e5ce118 to 2314a19 Compare April 2, 2024 15:50
This is an attempt at deepening the understanding of type promotions and
operators for basic types. This should address most of the ideas in
issue hsf-training#157.

Fix hsf-training#157
@hageboeck hageboeck merged commit 476d7db into hsf-training:master Apr 2, 2024
91 checks passed
@hageboeck hageboeck deleted the basicTypes branch April 2, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operator exercise for first day?
2 participants