Compare commits
No commits in common. '7d7ac8ec8214d52a9f4c46358241539a05e04226' and 'd38063dd9d471b647beb9faab147e1f47bd29eff' have entirely different histories.
7d7ac8ec82
...
d38063dd9d
@ -1,39 +0,0 @@ |
|||||||
#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; |
|
||||||
} |
|
@ -1,51 +0,0 @@ |
|||||||
#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; |
|
||||||
} |
|
@ -1,37 +0,0 @@ |
|||||||
#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; |
|
||||||
} |
|
@ -1,28 +0,0 @@ |
|||||||
#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; |
|
||||||
} |
|
@ -1,14 +0,0 @@ |
|||||||
#include <stdio.h> |
|
||||||
|
|
||||||
int main() |
|
||||||
{ |
|
||||||
int a = 1; |
|
||||||
int * p = &a; |
|
||||||
|
|
||||||
a += 1; |
|
||||||
*p += 1; |
|
||||||
|
|
||||||
printf("Value of a: %d\n", a); |
|
||||||
|
|
||||||
return 0; |
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
#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; |
|
||||||
} |
|
@ -1,30 +0,0 @@ |
|||||||
#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…
Reference in new issue