Skip to content

Commit ab116b2

Browse files
committed
finished 4, added 5
1 parent e6bf718 commit ab116b2

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

3-data-types.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44

55
int main(void)
66
{
7-
//* char variables
7+
//* Char variables
88
char mychar = 'C'; //* Must be inside single quotation marks
9-
printf("%c\n", mychar);
9+
printf("Char: %c\n", mychar);
1010

1111
//* array of chars
1212
//* when assigning a value to an array of characters it must be inside double quotation marks
1313
char mystring[6] = "Hello"; //* This string can have a maximum of 5 chars, the final one is for the null character.
14-
printf("%s\n", mystring);
14+
printf("Fixed-Size string: %s\n", mystring);
1515

1616
char mysecondstring[] = "I am free!"; //* Strings can also be specified without a specific size
17-
printf("%s\n", mysecondstring);
17+
printf("A string with no specified length: %s\n", mysecondstring);
1818

1919
//* Boolean Variables
20-
bool myboolean = true; //* A boolean variable can only be either true, or false. Which is represented as the integer 1 for true, and 0 for false
21-
printf("%d\n", myboolean); //* This will print 1, because the value is true
20+
bool myboolean = true; //* A boolean variable can only be either true, or false. Which is represented as the integer 1 for true, and 0 for false
21+
printf("Boolean: %d\n", myboolean); //* This will print 1, because the value is true
2222

2323
//* Numeric Variables
2424
int myinteger = 100; //* Integer values can be between -2,147,483,648 to +2,147,483,647
25-
printf("%d\n", myinteger);
25+
printf("Integer: %d\n", myinteger);
2626

2727
float myfloat = 100.1254; //* 6 decimal points
28-
printf("%f\n", myfloat);
28+
printf("Float: %f\n", myfloat);
2929

3030
double mydouble = 10000.545455; //* 15 decimal points
31-
printf("%lf\n", mydouble);
31+
printf("Double: %lf\n", mydouble);
3232
return 0;
3333
}
3434

4-advanced-data-types-part-1.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,24 @@
33
//* 4 - Advanced Data Types, Part 1
44
int main(void)
55
{
6+
//* char variables
7+
unsigned char mychar = 68; //* Can hold a value from 0 to 255 (1 Byte). This will print out "D" because 68 corresponds to D in the ascii table
8+
printf("Char: %c\n", mychar);
9+
//* Numeric Variables
10+
long long int mysuperlongint = 5999999999; //* long long int holds 8 bytes of data, and can have values between -9 quintillion to 9 quintillion, and we use the format specifier %lld
11+
unsigned long long int myunsignedlonglongint = 35345565343454364; //* same as long long int but with no negative values, we use the format specifier %llu
12+
unsigned int myint = 2; //* Same as int but doesn't hold negative values
13+
short int myshortint = 3; //* Unlike normal int which hold 4 bytes of data, a short int can only hold 2 bytes
14+
unsigned short int myunsignedshortint = 5; //* Same as short int but doesn't hold negative values
15+
printf("Long long int: %lld\nUnsigner long long int: %llu\nUnsigned int: %u\nShort int: %d\nUnsigned short int: %d\n",
16+
mysuperlongint, myunsignedlonglongint, myint, myshortint, myunsignedshortint); //* Unsigned int uses the format specifier %u, not %d
17+
618
return 0;
7-
}
19+
}
20+
/*
21+
!Note
22+
* The keyword unsigned means that the value cannot be negative number
23+
* By default datatypes are signed, meaning they can hold negative and positive values
24+
* You can declare short int without typing the "int" keyword (example: short myint = 2;)
25+
* Normal int data type is considered long int, that is why there is another data type long long, to represent huge numbers
26+
*/

5-advanced-data-types-part-2.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
//* 5 - Advanced Data Types, Part 2
4+
int main(void)
5+
{
6+
return 0;
7+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ Pull requests are most welcome <3
2727
| [2-variables-overview.c](https://github.com/mohabgabber/seecheatsheet/blob/main/2-variables-overview.c) | A very simple introduction to initializing variables and assigning values to them. |
2828
| [3-data-types.c](https://github.com/mohabgabber/seecheatsheet/blob/main/3-data-types.c) | Basic Data types in C explained |
2929
| [4-advanced-data-types-part-1.c](https://github.com/mohabgabber/seecheatsheet/blob/main/4-advanced-data-types-part-1.c) | Advanced Data Types, Part 1 |
30+
| [5-advanced-data-types-part-2.c](https://github.com/mohabgabber/seecheatsheet/blob/main/5-advanced-data-types-part-2.c) | Advanced Data Types, Part 2 |
3031
## Note
3132
I recommend installing the extension "Better Comments" in vs code to highlight the comments and make them easier to read.

0 commit comments

Comments
 (0)