0% found this document useful (0 votes)
9 views3 pages

#Include

Uploaded by

daniel07302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

#Include

Uploaded by

daniel07302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

포인터변수 복습

#include <stdio.h>

int main() {
char a=‘A’;
a=A, &a=…24, (&a)+1=…25
printf(“a=%c, &a=%p, (&a)+1=%p\n”, a, &a, (&a)+1); b=10, &b=…44, (&b)+1=…48
c=0.50, &c=…64, (&c)+1=…68
d=0.80, &d=…88, (&d)+1=…90
int b=10;
printf(“b=%d, &b=%p, (&b)+1=%p\n”, b, &b, (&b)+1);

float c=0.5;
printf(“c=%.2f, &c=%p, (&c)+1=%p\n”, c, &c, (&c)+1);

double d=0.8;
printf(“d=%.2lf, &d=%p, (&d)+1=%p\n”, d, &d, (&d)+1);

return 0;
}
Lab to submit: 1) Swap function
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void swap(int *pX, int *pY) {


두 수를 입력: 10 20
// Fill this part: swap *pX and *pY
swap() 이전: 10 20
} swap() 이후: 20 10

int main() {
int a, b;
printf(“두 수를 입력: “);
scanf(“%d %d”, &a, &b);

printf(“swap() 이전: a=%d, b=%d\n”, a, b);


swap(&a, &b);
printf(“swap() 이후: a=%d, b=%d\n”, a, b);

return 0;
}
Lab to submit: 2) Return two results
#include <stdio.h>

void line_params(int x1, int y1, int x2, int y2, double
*pSlope, double *pIntercept) {
// Fill this part: calculate slope and y intercept,
and return them
slope: -1.00, intercept: 3.00
}

int main() {
int x1=1, y1=2;
int x2=3, y2=0;

double slope=0.0, intercept=0.0;


line_params(x1, y1, x2, y2, &slope, &intercept);
printf(“slope: %.2lf, intercept: %.2lf\n”, slope,
intercept);

return 0;
}

You might also like