C语言快速回忆书签

1、编程开始

#include
#include
int main()
{




return 0;
}


return 0,将cpu使用权交个操作系统,int 返回一个整型.



2、输入输出

#include
#include
int main()
{
int i ,j,h[10];
printf("please input 10 numbers:");
for(i=0;i<10;i++)
{
  scanf("%d",&h[i])  ;
}
for(j=0;j<10;j++)
{
  printf("%d",h[j])  ;
}
return 0;
}

3、函数调用

#include /* function declaration */
int max(int num1, int num2);int main () {/* local variable definition */int a = 100;int b = 200;int ret;/* calling a function to get max value */ret = max(a, b);printf( "Max value is : %d\n", ret );return 0;
}/* function returning the max between two numbers */
int max(int num1, int num2) {/* local variable declaration */int result;if (num1 > num2)result = num1;elseresult = num2;return result; 
}

4、指针使用

#include int main () {int  var = 20;   /* actual variable declaration */int  *ip;        /* pointer variable declaration *///这里是定义ip = &var;  /* store address of var in pointer variable*/printf("Address of var variable: %x\n", &var  );/* address stored in pointer variable */printf("Address stored in ip variable: %x\n", ip );/* access the value using the pointer */printf("Value of *ip variable: %d\n", *ip );//这里是求指针的值return 0;
}

指针调用结构体

#include 
#include struct Books {char  title[50];char  author[50];char  subject[100];int   book_id;
};/* function declaration */
void printBook( struct Books *book );
int main( ) {struct Books Book1;        /* Declare Book1 of type Book */struct Books Book2;        /* Declare Book2 of type Book *//* book 1 specification */strcpy( Book1.title, "C Programming");strcpy( Book1.author, "Nuha Ali"); strcpy( Book1.subject, "C Programming Tutorial");Book1.book_id = 6495407;/* book 2 specification */strcpy( Book2.title, "Telecom Billing");strcpy( Book2.author, "Zara Ali");strcpy( Book2.subject, "Telecom Billing Tutorial");Book2.book_id = 6495700;/* print Book1 info by passing address of Book1 */printBook( &Book1 );/* print Book2 info by passing address of Book2 */printBook( &Book2 );return 0;
}void printBook( struct Books *book ) {printf( "Book title : %s\n", book->title);printf( "Book author : %s\n", book->author);printf( "Book subject : %s\n", book->subject);printf( "Book book_id : %d\n", book->book_id);
}
5、指针函数
#include
#include
int add(int x);
int main()
{   int (*fun)()=add;printf("%d",(*fun)(1));return 0;
}int add(int x){return x+1;}




拓展阅读:嵌入式笔试题:http://blog.sina.com.cn/s/blog_9f149699010133xz.html

6、结构体声明

struct  {

            int a;

           char  b;

            float  c;

}  x,y[20],*z;

x,y[20],*z为变量。


struct  SIMPLE {

            int a;

           char  b;

            float  c;

} ;

这个声明把标签SIMPLE和这个成员列表联系在一起,该声明并没有提供变量列表,所以并未创建任何变量。

创建变量:

  struct SIMPLE  x;

  struct SIMPLE  y[20],*z;


采用typedef

typedef struct {

int a;

char b ;

float c;

}Simple;


Simple x;

Simple y[20], *z;


举例子: CC2530

typedef struct
{
  osal_event_hdr_t hdr;     /* OSAL Message header */
  uint16 groupId;           /* Message's group ID - 0 if not set */
  uint16 clusterId;         /* Message's cluster ID */
  afAddrType_t srcAddr;     /* Source Address, if endpoint is STUBAPS_INTER_PAN_EP,
                               it's an InterPAN message */
  uint16 macDestAddr;       /* MAC header destination short address */
  uint8 endPoint;           /* destination endpoint */
  uint8 wasBroadcast;       /* TRUE if network destination was a broadcast address */
  uint8 LinkQuality;        /* The link quality of the received data frame */
  uint8 correlation;        /* The raw correlation value of the received data frame */
  int8  rssi;               /* The received RF power in units dBm */
  uint8 SecurityUse;        /* deprecated */
  uint32 timestamp;         /* receipt timestamp from MAC */
  uint8 nwkSeqNum;          /* network header frame sequence number */
  afMSGCommandFormat_t cmd; /* Application Data */
} afIncomingMSGPacket_t;


定义一个变量:

afIncomingMSGPacket_t    *MSGpkt;


  



本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部