Compare commits

..

7 Commits

  1. 13
      .vscode/tasks.json
  2. 39
      practice/lc_arrayAndPointers.c
  3. 51
      practice/lc_functionArgsByReference.c
  4. 37
      practice/lc_functionPointers.c
  5. 28
      practice/lc_pointerArithmetics.c
  6. 14
      practice/lc_pointers.c
  7. 19
      practice/lc_recursion.c
  8. 30
      practice/lc_structures.c

13
.vscode/tasks.json vendored

@ -70,13 +70,22 @@
"type": "cppbuild",
"label": "C/C++: gcc.exe 활성 파일 빌드",
"command": "C:/mingw64/bin/gcc.exe",
// main ()
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}\\*.c",
"${file}",
"-o",
"${fileDirname}\\bin\\${fileBasenameNoExtension}.exe"
"${fileDirname}\\bin\\${fileBasenameNoExtension}.exe",
],
// // main
// "args": [
// "-fdiagnostics-color=always",
// "-g",
// "${fileDirname}\\*.c",
// "-o",
// "${fileDirname}\\bin\\${fileBasenameNoExtension}.exe"
// ],
"options": {
"cwd": "C:/mingw64/bin"
},

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
char vowels[] = { 'A', 'E', 'I', 'O', 'U' };
char* pvowels = vowels;
printf("Point the addresses\n");
for (int i = 0; i < 5; i++)
{
printf("&vowels[%d]: %p, pvowels + %d: %p, vowels + %d: %p\n", i, &vowels[i], i, pvowels + i, i, vowels + i);
}
printf("\nPoint the values\n");
for (int i = 0; i < 5; i++)
{
printf("vowels[%d]: %c, *(pvowels + %d): %c, *(vowels + %d): %c\n", i, vowels[i], i, *(pvowels + i), i, *(vowels + i));
}
// Dynamic malloc for array
int n = 4;
char* parr = (char*)malloc(n * sizeof(char));
parr[0] = 'L';
parr[1] = 'o';
parr[2] = 'V';
parr[3] = 'e';
for (int i = 0; i < n; i++)
{
printf("%c", parr[i]);
}
printf("\n");
free(parr);
return 0;
}

@ -0,0 +1,51 @@
#include <stdio.h>
void addone(int n)
{
n++;
}
void addoneByRef(int* n)
{
(*n)++;
}
typedef struct
{
int x;
int y;
} Point;
void move1(Point* p)
{
(*p).x++;
(*p).y++;
}
// 약어
void move2(Point* p)
{
p->x++;
p->y++;
}
int main()
{
int n = 0;
printf("Step0: %d\n", n);
addone(n);
printf("Step2: %d\n", n);
addoneByRef(&n);
printf("Step2: %d\n", n);
printf("\n");
Point pt = { 1, 1 };
printf("Step0 pt.x: %d, pt.y: %d\n", pt.x, pt.y);
move1(&pt);
printf("Step1 pt.x: %d, pt.y: %d\n", pt.x, pt.y);
move2(&pt);
printf("Step2 pt.x: %d, pt.y: %d\n", pt.x, pt.y);
return 0;
}

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
void someFunction(int arg)
{
printf("This is someFunction being called and arg is: %d\n", arg);
printf("Now, leaving the funciton!\n");
}
int compare(const void* left, const void* right)
{
return (*(int*)right - *(int*)left);
}
int main()
{
void (*pf)(int);
pf = &someFunction;
printf("We are about to call someFunction() using a pointer!\n");
(pf)(5);
printf("Wow that was cool!");
int (*cmp)(const void*, const void*);
cmp = &compare;
int iarray[] = {1,2,3,4,7,5,6,9,8};
qsort(iarray, sizeof(iarray) / sizeof(*iarray), sizeof(*iarray), cmp);
int c = 0;
while (c < sizeof(iarray) / sizeof(*iarray))
{
printf("%d\t", iarray[c]);
c++;
}
return 0;
}

@ -0,0 +1,28 @@
#include <stdio.h>
int main()
{
int intarray[5] = { 10, 20, 30, 40, 50 };
for (int i = 0; i < 5; i++)
{
printf("intarray[%d] has value %d - and address @ %x\n", i, intarray[i], &intarray[i]);
}
int* intpointer = &intarray[3];
printf("address %x - has value %d\n", intpointer, *intpointer);
intpointer++;
printf("address %x - has value %d\n", intpointer, *intpointer);
intpointer--;
printf("address %x - has value %d\n", intpointer, *intpointer);
intpointer -= 2;
printf("address %x - has value %d\n", intpointer, *intpointer);
intpointer += 2;
printf("address %x - has value %d\n", intpointer, *intpointer);
return 0;
}

@ -0,0 +1,14 @@
#include <stdio.h>
int main()
{
int a = 1;
int * p = &a;
a += 1;
*p += 1;
printf("Value of a: %d\n", a);
return 0;
}

@ -0,0 +1,19 @@
#include <stdio.h>
unsigned int multiply(unsigned int x, unsigned int y)
{
if (x == 1)
return y;
if (x > 1)
return y + multiply(x - 1, y);
return 0;
}
int main()
{
printf("3 times 100 is %d", multiply(3, 100));
return 0;
}

@ -0,0 +1,30 @@
#include <stdio.h>
struct Point
{
int x;
int y;
};
typedef struct
{
char* brand; // 동적 할당을 위한 처리
int model;
} Vehicle;
int main()
{
struct Point pt;
pt.x = 10;
pt.y = 5;
Vehicle vc;
vc.brand = "Ford";
vc.model = 2025;
printf("pt.x: %d\n", pt.x);
printf("pt.y: %d\n", pt.y);
printf("\n");
printf("vc.brand: %s\n", vc.brand);
printf("vc.model: %d\n", vc.model);
}
Loading…
Cancel
Save