从函数返回多个值有人能告诉我如何从函数返回多个值吗?请举例说明一下?
3 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
/* method 1 */struct Bar{ int x; int y;};struct Bar funct();struct Bar funct(){ struct Bar result; result.x = 1; result.y = 2; return result;}/* method 2 */void funct2(int *x, int *y);void funct2(int *x, int *y){ /* dereferencing and setting */ *x = 1; *y = 2;}int main(int argc, char* argv[]) { struct Bar dunno = funct(); int x,y; funct2(&x, &y); // dunno.x == x // dunno.y == y return 0;}
守着一只汪
TA贡献1872条经验 获得超3个赞
typedef struct blah{ int a; float b;} blah_t;blah_t my_func(){ blah_t blah; blah.a = 1; blah.b = 2.0f; return blah;}
void my_func(int *p_a, float *p_b){ *p_a = 1; *p_b = 2.0f;}
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
struct addr { // struct type to represent mailing address char *name; int streetNumber; char *streetName; char *unitNumber; char *city; char state[3]; int ZIP;};struct addr getAddressFor(char *name) {...}struct point2D { int x; int y;};struct polygon2D { size_t numPoints; struct point2D *points;};struct point2D getOrigin(struct polygon2D poly) {...}
*scanf()
strtod()
strtol()
char *str = "3.14159";double value;char *chk;value = strtod(str, &chk);if (!isspace(*chk) && *chk != 0) printf("Non-numeric character found in %s\n", str);
typedef enum {SUCCESS, REQ_GARBLED, NO_DATA_OF_TYPE, EMPTY, ERROR} Status;typedef struct bounds {...} Bounds; tyepdef struct metadata { size_t bytesRead; size_t elementsRead; size_t rows; size_t cols;} Metadata;typedef struct elevations { size_t numValues; short *elevations;} Elevations;Elevations elevs;Metadata meta;Bounds b = ...; // set up search boundaryStatus stat = getElevationsFor(b, &elevs, &meta);
- 3 回答
- 0 关注
- 460 浏览
添加回答
举报
0/150
提交
取消