[Note] C learn
2018-02-06 11:58
218 查看
函数指针 & 指针函数 http://blog.csdn.net/ameyume/article/details/8220832 函数输出多个值#1 结构体#include<stdio.h>struct t{int a,b;};struct t fun(int c,int d){struct t res;res.a=c+d;res.b=c*d;return res;}int main (void){struct t n=fun(5,6);printf ("%d\n",n.a);printf ("%d\n",n.b);return 0;}out put will be 11 and 30.# 指针
//变相返回圆的面积、周长 void cir(double r,double *area,double *girth) // (输入,输出1,输出2) { *area=PI*r*r; *girth=PI*r*2; } int main(int argc, char *argv[]) { double r=10.2; double s=0,g=0; struct test *t1=getTest(); if(!t1) return 1; cir(r,&s,&g); (输入,输出1,输出2) printf("area=%f,girth=%f\n",s,g); printf("%d,%s\n",t1->x,t1->str); if(t1) { free(&t1); t1=NULL; } return 0; }
%%%%%%%%%%%%%%
结构体 size:
在缺省对齐下我先给你说下三条准则吧,【1】结构体变量的首地址能够被其最宽基本类型成员的大小所整除【2】结构体每个成员相对于结构体首地址的偏移量是成员大小的整数背【3】结构体的总大小为结构体最宽基本类型成员大小的整数背以上都是结构体中只有基本类型时的缺省对齐方式,当有嵌套复合成员时,【2】改为:复合成员相对于结构体首地址偏移量是复合成员最宽基本类型大小的整数背所以分析你上面的typedef struct node{int a[100];char b;}kkk;先是第一成员400个字节,然后还有个char一个字节,为了满足第第三条准则,即总大小401为最宽基本类型的整数背,明显401不是最宽基本类型int(4)的整数背,所以总大小为404
相关文章推荐
- [Learn Note] Java Script Guide Line
- Spring learn note
- JAVA NET PROGRAM LEARN NOTE
- Note of "Learn Python the HardWay"
- How to Learn Note
- note:some learn remark
- [Learn Note]2012-01-29
- Spring learn note 2
- Spring learn note 4
- [Learn Note] MSBuild
- Spring learn note 3
- Learn note(cpp): take care when use new in a code block.
- [Learn Note]Assembly Manifest
- Php learn note
- c programming language learn note 4
- python scikit-learn, note 20161209
- [LearnNote] JSON
- Learn Python The Hard Way exercise 41 note
- Studying note of GCC-3.4.6 source (39)
- READING NOTE: PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection