#include <stdio.h>
#include <stdlib.h>
int main() {
int* pa = NULL;
double* pb = NULL;
pa = (int*) malloc(sizeof(int)); // (int*) (int) ํ์๋ณํ์ฐ์ฐ์
pb = (double*) malloc(sizeof(double));
*pa = 10;
*pb = 3.14;
printf("int : %d\n", *pa);
printf("double : %g\n", *pb);
free(pa);
free(pb);
}
#include <stdio.h>
#include <stdlib.h>
int* AllocInt() {
return (int*)malloc(sizeof(int));
}
double* AllocDouble() {
return (double*)malloc(sizeof(double));
}
void SetInt(int* p, int data) {
*p = data;
}
void SetDouble(double* p, double data) {
*p = data;
}
void PrintInt(int data) {
printf("int : %d\n", data);
}
void PrintDouble(double data) {
printf("double : %g\n", data);
}
void FreeInt(int* p) {
free(p);
}
void FreeDouble(double* p) {
free(p);
}
int main() {
int* pa = NULL;
double* pb = NULL;
pa = AllocInt();
pb = AllocDouble();
SetInt(pa, 10); // SetInt(&*pa, 10);
SetDouble(pb, 3.14);
PrintInt(*pa);
PrintDouble(* pb);
FreeInt(pa);
FreeDouble(pb);
}
#include <stdio.h>
#include <stdlib.h>
void AllocInt(int** pp) {
*pp = (int*)malloc(sizeof(int));
}
void AllocDouble(double** pp) {
*pp = (double*)malloc(sizeof(double));
}
void SetInt(int* p, int data) {
*p = data;
}
void SetDouble(double* p, double data) {
*p = data;
}
void PrintInt(int data) {
printf("int : %d\n", data);
}
void PrintDouble(double data) {
printf("double : %g\n", data);
}
void FreeInt(int* p) {
free(p);
}
void FreeDouble(double* p) {
free(p);
}
int main() {
int* pa = NULL;
double* pb = NULL;
AllocInt(&pa);
AllocDouble(&pb);
SetInt(pa, 10); // SetInt(&*pa, 10);
SetDouble(pb, 3.14);
PrintInt(*pa);
PrintDouble(*pb);
FreeInt(pa);
FreeDouble(pb);
}
#include <stdio.h>
#include <stdlib.h>
int* AllocIntArray(int capacity) {
return (int*)malloc(sizeof(int) * capacity);
}
void InitIntArray(int* pa, int size) {
for (int i = 0; i < size; ++i)
pa[i] = i + 1;
}
void PrintIntArray(int* pa, int size) {
for (int i = 0; i < size; ++i)
printf("data : %d\n", pa[i]);
}
void FreeIntArray(int* pa) {
free(pa);
}
int main() {
int* pa = AllocIntArray(10);
InitIntArray(pa, 10);
PrintIntArray(pa, 10);
FreeIntArray(pa);
}
#include <stdio.h>
struct Point {
int x;
int y;
};
int main() {
int n = 10;
Point pt = { 2,3 };
printf("size : %d\n", sizeof(pt.x));
printf("size : %d\n", sizeof(pt));
}
#include <stdio.h>
struct Point {
int x;
int y;
};
int main() {
int n = 10;
Point pt = { 2,3 };
printf("size : %d\n", sizeof(pt.x));
printf("size : %d\n", sizeof(pt));
int* p1 = &pt.x;
Point* p2 = &pt;
printf("%p %p\n", p1, p1 + 1);
printf("%p %p\n", p2, p2 + 1);
}
#include <stdio.h>
struct Point {
int x;
int y;
};
int main() {
Point pt1 = { 2,3 };
Point pt2 = { 4,5 };
printf("(%d, %d)\n", pt1.x, pt1.y);
printf("(%d, %d)\n", pt2.x, pt2.y);
}
#include <stdio.h>
struct Point {
int x;
int y;
};
void PrintPoint(Point pt) {
printf("(%d, %d)\n", pt.x, pt.y);
}
int main() {
Point pt1 = { 2,3 };
Point pt2 = { 4,5 };
PrintPoint(pt1);
printf("(%d, %d)\n", pt2.x, pt2.y);
}
#include <stdio.h>
struct Point //Point ๊ตฌ์กฐ์ฒด ์ ์
{
int x;
int y;
};
void PrintPoint(Point pt) {
printf("(%d, %d)\n", pt.x, pt.y);
}
int main() {
Point pt1 = { 2,3 };
Point pt2 = { 4,5 };
PrintPoint(pt1);
PrintPoint(pt2);
}
#include <stdio.h>
struct Point
{
int x;
int y;
};
void PrintPoint(Point* p) {
printf("(%d, %d)\n", p->x, p->y);
}
int main() {
Point pt1 = { 2,3 };
Point pt2 = { 4,5 };
PrintPoint(&pt1);
PrintPoint(&pt2);
}