
C (gcc)
alanlj
刚入门,想学点东西
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
万年历
包含三文件w.c, date.h, date.c。其中w文件为主文件w.c文件内容,包含date.h#include "date.h"void main(){ Date date; int choose; Input(&date); Show(&date,&choose); }date.h声明函数/* 定义日期 */typedef struct dat原创 2012-08-30 23:11:41 · 547 阅读 · 0 评论 -
第一个C程序内嵌汇编(Linux下)
近期在学习linux下C编程,第一个内嵌汇编语言的C程序,其实很简单。 #include /** the standard:* __asm__(assembler template :output operands :input operands :list of clobbered registers )*/int main(void){ in原创 2013-03-10 17:27:43 · 588 阅读 · 0 评论 -
宏与预处理
#include #define C#define Max(x, y) (x > y ? x:y)int main(void){#ifndef _def#define _def int c; //把c的定义用保护宏保护起来#endif#ifdef _def //相当于判断变量c是否定义 printf("%d\n ", Max(2, 4));#原创 2013-03-15 21:27:56 · 748 阅读 · 0 评论 -
宏的简单应用(得出数组中的最大值)
#include #define MAX(x, y) (x > y ? x : y) int a[] = {5, 3, 54, 565, 24, 75};int max(int n){ //用递归的方式从前面开始比较a[]中数值 return n == 0 ? a[0] : MAX(a[n], max(n - 1));}int main(void){int原创 2013-03-15 21:04:09 · 793 阅读 · 0 评论 -
宏函数中#, ##及参数的简单应用
#include //#的作用:下面代码相当于声明一个字符串STR[],s就是STR[]中的字符 #define STR(s) # s//##作用:将a, b 合成一个新的变量c(假设为c, c = ab). Note:c必须有声明或为常数,如 STR1(1, 2) = 12#define STR1(a, b) a ## b//...作用:...表示可变参数,而后面原创 2013-03-16 17:23:51 · 1337 阅读 · 0 评论 -
用特殊标示符编写简单的测试程序
自己动手写的一个测试执行语句对错的程序,C函数库中其实已有。assert.h文件,定义assert宏函数,并实现测试功能/** assert是用来判断test执行是否出错,若出错则输出错误文件及行号*/#undef assert //如果以前定义了宏assert, 取消#ifdef NDUBUG //若定义了宏NDUBUG,NDEBUG一般是用来使宏assert失效原创 2013-03-16 20:33:36 · 586 阅读 · 0 评论 -
指针在内存分配中的简单应用
头文件 point.h#ifndef DP#define DPchar *get_day(int);void get_a_day(const char**);#endif函数文件 point.c#include "doublepoint.h"#include static const char *msg[] = { "Sunday", "Monday", "Tuesday原创 2013-06-01 11:40:27 · 565 阅读 · 0 评论 -
指针与数组 C
过些天要去一个公司面试,在网上下了个c语言的面试题,看到一个很有趣的题目,是有关于数组指针的,题目如下 #include int main(void){ int a[5] = {1, 2, 3, 4, 122}; int *ptr = (int *)(&a + 1); printf("%d %d\n", *(a + 1), *(ptr - 1));原创 2013-08-13 11:11:59 · 542 阅读 · 0 评论