hwpplayer1 branch initial commit

This commit is contained in:
Mert Gör 🇹🇷 2024-02-14 08:57:10 +03:00
parent 6a85607ff0
commit 8bd56af0aa
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
17 changed files with 4 additions and 620 deletions

View File

@ -1,3 +1,7 @@
2024-02-14 Mert Gör <mertgor@masscollabs.xyz>
* c-basic/C.pdf: CSD Derneği C temel notu tekrar C-Basic klasörüne eklendi ancak hwpplayer1 dalı için eklendi. Örnekler özgün olarak yeniden yazılacak.
2024-02-04 Mert Gör <mertgor@masscollabs.xyz>
* c-basic/global-variable-scope.c (foo): global variable and local variable explained with two different a variable value

View File

@ -1,45 +0,0 @@
/**
foo.c - foo example
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int foo()
{
printf("I am foo\n");
}
int main()
{
foo();
}
/**
In the written book it is foo() and main() and it returns this warning
~/Projects/hwpplayer1/c-course/c-basic $ gcc foo.c
foo.c:3:1: warning: return type defaults to int [-Wimplicit-int]
3 | foo()
| ^~~
foo.c:8:1: warning: return type defaults to int [-Wimplicit-int]
8 | main()
| ^~~~
**/

View File

@ -1,39 +0,0 @@
/**
global-variable-scope.c - global variable and their scopes explained
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int a;
void foo(){
a = 10;
}
int main(){
a = 30;
printf("%d\n", a); /* a is 30*/
foo();
printf("%d\n", a); /* a is 10*/
return 0;
}

View File

@ -1,29 +0,0 @@
/**
helloworld.c - hello world example
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
printf("Hello World\n");
return 0;
}

View File

@ -1,39 +0,0 @@
/**
initialization-variable.c - Swap Algorithm with initialized variables example
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
int a = 10;
int b = 20;
int temp;
temp = a;
a = b;
b = temp;
printf("a value is: %d\n", a);
printf("a value is: %d\n", b);
return 0;
}

View File

@ -1,40 +0,0 @@
/**
local-variable-global-variable-scope.c - local variable and global variable explained
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main() {
int a;
a = 10;
{
int a;
a = 20;
printf("%d\n", a); /* a value is 20*/
}
printf("%d\n",a); /* a value is 10 because it comes from the global variable a value*/
return 0;
}

View File

@ -1,41 +0,0 @@
/**
local-variable-scope.c - local variable and global variable explained
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main() {
int a;
{
int b;
b = 20;
a = 10;
printf("a = %d, b = %d\n", a, b); /* correct */
}
printf("a = %d\n", a); /* correct */
printf("b = %d\n", b); /* wrong */
return 0;
}

View File

@ -1,39 +0,0 @@
/**
on-return.void.c - if we pass void then it means function has no return value, and those functions are void functions
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
void foo() {
printf("foo\n");
}
int main() {
printf("I am main\n");
foo();
return 0;
}

View File

@ -1,31 +0,0 @@
/**
on-return.2.c - explaining return value : "without return same result exists"
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main() {
printf("I am main\n");
return 0; /* without this we'll see the same result*/
}

View File

@ -1,41 +0,0 @@
/**
on-return.c - explaining return value
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int foo() {
printf("foo example\n");
printf("we can access this code\n"); /*reachable code! */
return 100;
printf("unreachable code\n"); /*unreachable code! */
}
int main() {
int result;
result = foo() * 2;
printf("%d\n", result);
return 0;
}

View File

@ -1,37 +0,0 @@
/**
print_variables.c - print variables with different ways
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
int a = 10;
int b = 20;
// int a = 10, b = 20; is another option
printf("a = %d, b = %d\n", a, b);
printf("a = %d, b = %d\n", b, a);
printf("a and b printed together = %d%d\n", a, b);
return 0;
}

View File

@ -1,39 +0,0 @@
/**
scanf-a-b-c-double.c - set a,b,c double variables, read a and b with scanf function and then pass addition of a and b to c variable and print c variable
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
double a,b,c;
printf("a variable :");
scanf("%lf", &a);
printf("b variable :");
scanf("%lf", &b);
c = a + b;
printf("a + b = %f\n", c);
return 0;
}

View File

@ -1,36 +0,0 @@
/**
scanf-example-two-variables.c - scanf example with two variables
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
int a;
int b;
printf("enter two variables/numbers: ");
scanf("%d%d", &a, &b);
printf("a = %d, b = %d\n", a, b);
return 0;
}

View File

@ -1,35 +0,0 @@
/**
scanf-example.c - gettıng input source via scancf
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
int a;
printf("Enter a number: ");
scanf("%d", &a);
printf("The number you typed is : %d\n", a);
return 0;
}

View File

@ -1,41 +0,0 @@
/**
scanf-float.c - Scanf reads float as %f and double %lf
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main() {
float f;
double d;
printf("enter your float variable: ");
scanf("%f", &f);
printf("enter your double variable: ");
scanf("%lf", &d);
printf("f = %f, d = %f\n", f, d);
return 0;
}

View File

@ -1,35 +0,0 @@
/**
scanf-hex.c - Scanf accepts the int variable as hex if we pass %x
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main(){
int a;
int b;
printf("enter a number : ");
scanf("%x", &a);
printf("a = %d\n", a);
return 0;
}

View File

@ -1,53 +0,0 @@
/**
scope.c - scope and variables explained
Copyright (C) 2023-2024 Mert Gör and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Feel free to send an email to mertgor@masscollabs.xyz for your questions
**/
#include <stdio.h>
int main() {
int a;
{
int b;
b = 20;
a = 10;
printf("a : %d, b : %d\n", a, b); // correct way to get done the job/task
}
printf("a : %d\n", a); // correct way to get done the job/task for a variable
// printf("b : %d\n", b); // error !
/**
~/Projects/hwpplayer1/c-course/c-basic $ gcc scope.c
scope.c: In function main:
scope.c:35:22: error: b undeclared (first use in this function)
35 | printf("b : %d\n", b); // error !
| ^
scope.c:35:22: note: each undeclared identifier is reported only once for each function it appears in
**/
return 0;
}
/**
~/Projects/hwpplayer1/c-course/c-basic $ ./a.out
a : 10, b : 20
a : 10
**/