易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : c

C函数指针总结

本文仅限于C,主要自己老忘。别的废话少说。
1.Basic
首先考虑函数在函数体内的定义,如下: 
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 int add(int,int); 
 int def(int, int);
 printf("%d\n", add(1,3));
 printf("%d\n", def(3,1));
 return 0;
}
 
int add(int a, int b) { return a+b; }
int def(int a, int b)   { return a-b; }
定义一个函数指针:
 ReturnValue  (*fun_ptr)();
上面的代码用函数指针掉用如下:
 
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 int add(int,int); 
 int def(int, int);
 int (*p)();
 
 p = add;
 printf("%d\n", p(1,3));
 
 p = def;
 printf("%d\n", p(3,1));
 return 0;
}
 
int add(int a, int b) { return a+b; }
int def(int a, int b)   { return a-b; }
到此为止貌似没有什么用,不过可以考虑一个更加具有美感的写法,如下:
 
#include <stdio.h>
#inclu ......

C程序设计的常用算法


  算法(Algorithm):计算机解题的基本思想方法和步骤。算法的描述:是对要解决一个问题或要完成一项任务所采取的方法和步骤的描述,包括需要什么数据(输入什么数据、输出什么结果)、采用什么结构、使用什么语句以及如何安排这些语句等。通常使用自然语言、结构化流程图、伪代码等来描述算法。
  一、计数、求和、求阶乘等简单算法
  此类问题都要使用循环,要注意根据问题确定循环变量的初值、终值或结束条件,更要注意用来表示计数、和、阶乘的变量的初值。
  例:用随机函数产生100个[0,99]范围内的随机整数,统计个位上的数字分别为1,2,3,4,5,6,7,8,9,0的数的个数并打印出来。
  本题使用数组来处理,用数组a[100]存放产生的确100个随机整数,数组x[10]来存放个位上的数字分别为1,2,3,4,5,6,7,8,9,0的数的个数。即个位是1的个数存放在x[1]中,个位是2的个数存放在x[2]中,……个位是0的个数存放在x[10]。
void main()
{
int a[101],x[11],i,p;
for(i=0;i<=11;i++)
x=0;
for(i=1;i<=100;i++)
{
a=rand() % 100;
printf("%4d",a);
if(i%10==0)printf("\n");
}
for(i=1;i<=100;i++)
{
p=a%10;
if ......

C中的空


1.   什么是空指针常量(null pointer constant)?
[ 6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
这里告诉我们:0、0L、'\0'、3 - 3、0 * 17 (它们都是“integer constant expression”)以及 (void*)0 (tyc:我觉得(void*)0应该算是一个空指针吧,更恰当一点)等都是空指针常量(注意 (char*) 0 不叫空指针常量,只是一个空指针值)。至于系统选取哪种形式作为空指针常量使用,则是实现相关的。一般的 C 系统选择 (void*)0 或者 0 的居多(也有个别的选择 0L);至于 C++ 系统,由于存在严格的类型转化的要求,void* 不能象 C 中那样自由转换为其它指针类型,所以通常选 0 作为空指针常量(tyc: C++标准推荐),而不选择 (void*)0。
2.   什么是空指针(null pointer)?
[6.3.2.3-3] If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
因此,如果 p 是一个指针变量,则 p = 0;、p = 0L;、 ......

C/C++学习笔记[01].纵向打印整数

#include <stdio.h>
#include <string.h>
#include <math.h>
#define BASE 10
int intlen(long n);
int main()
{
int i, j, num, sz;
i = j = num = sz = 0;
if (!scanf("%d", &num) || num <= 0) {
printf("invalid input\n");
return 1;
}
sz = intlen(num);
for (i = sz; i > 0; i--) {
for (j = 1; j <= num; j++) {
printf("%d",(j % (int) (pow(BASE,i))) / (int) (pow(BASE,i - 1)));
}
printf("\n");
}
return 0;
}
int intlen(long n)
{
return log10(fabs(n)) + 1;
}
/* vim: set ts=4 sw=4: */

从标准输入接收一个大于0的整数,竖向打印1-这个数之间的数
用到了对数函数取整数的位数,取模运算,整除运算,指数运算 ......

C/C++学习笔记[01].纵向打印整数

#include <stdio.h>
#include <string.h>
#include <math.h>
#define BASE 10
int intlen(long n);
int main()
{
int i, j, num, sz;
i = j = num = sz = 0;
if (!scanf("%d", &num) || num <= 0) {
printf("invalid input\n");
return 1;
}
sz = intlen(num);
for (i = sz; i > 0; i--) {
for (j = 1; j <= num; j++) {
printf("%d",(j % (int) (pow(BASE,i))) / (int) (pow(BASE,i - 1)));
}
printf("\n");
}
return 0;
}
int intlen(long n)
{
return log10(fabs(n)) + 1;
}
/* vim: set ts=4 sw=4: */

从标准输入接收一个大于0的整数,竖向打印1-这个数之间的数
用到了对数函数取整数的位数,取模运算,整除运算,指数运算 ......

c默认是传值的

在c中,参数默认是传值的,即在参数入栈时被复制一份
。在函数里面修改这些参数,不会影响外面的调用者。
例如
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void get_str(char * p)
{
    p = (char *)malloc(sizeof("abcd"));
    strcpy(p , "abcd");
    return ;
}
int main()
{
    char * p = NULL;
    get_str(p);
    printf("p = %p\n", p);
    return 0;
}
分析:
在main函数里面初始化指针p位nuLL,虽然get_str函数是接受的指针,按照上面的说法,我们在栈中复制的是p指向内容的地址,传给函数get_str,在函数里面我们又重新修改了这个地址,而不是修改这个地址的内容,故外面就不起作用。 ......

C/C++运行中的一些问题及其解决

本人在做毕设的时候遇到的一些问题,在这里总结一下,希望会对大家有些帮助~有不足之处还望指出,大家共同进步^_^
 一、基本介绍:
1.运行环境VC6.0(Microsoft Visual C++ 6.0)(http://40.duote.org/microsoft_visualc6.zip)
2.课题相关内容:AVS视频编码
二、出现的问题及解决方法:
1.问题:
fatal error C1083:"Cannot open include file: 'Dshow.h': No such file or directory执行 cl.exe 时出错"
解决:
安装DirectX SDK(Nov_08版)( http://download.microsoft.com/download/5/8/2/58223f79-689d-47ae-bdd0-056116ee8d16/DXSDK_Nov08.exe)
Platform SDK(PSDK-x86)(http://download.microsoft.com/download/a/5/f/a5f0d781-e201-4ab6-8c6a-9bb4efed1e1a/PSDK-x86.exe)
在Tools->Option的选项卡directories中增加相应项目。
在Include files增加DirectX,DirectShow的Include路径,在Library files中增加DirectX,DirectShow的Lib路径。
------------------------------------------------------------------
2. 问题:
fatal error C1083: Cannot open include file: 'dxtrans.h': No such file or directory
解决:
安装DX ......

C/C++运行中的一些问题及其解决

本人在做毕设的时候遇到的一些问题,在这里总结一下,希望会对大家有些帮助~有不足之处还望指出,大家共同进步^_^
 一、基本介绍:
1.运行环境VC6.0(Microsoft Visual C++ 6.0)(http://40.duote.org/microsoft_visualc6.zip)
2.课题相关内容:AVS视频编码
二、出现的问题及解决方法:
1.问题:
fatal error C1083:"Cannot open include file: 'Dshow.h': No such file or directory执行 cl.exe 时出错"
解决:
安装DirectX SDK(Nov_08版)( http://download.microsoft.com/download/5/8/2/58223f79-689d-47ae-bdd0-056116ee8d16/DXSDK_Nov08.exe)
Platform SDK(PSDK-x86)(http://download.microsoft.com/download/a/5/f/a5f0d781-e201-4ab6-8c6a-9bb4efed1e1a/PSDK-x86.exe)
在Tools->Option的选项卡directories中增加相应项目。
在Include files增加DirectX,DirectShow的Include路径,在Library files中增加DirectX,DirectShow的Lib路径。
------------------------------------------------------------------
2. 问题:
fatal error C1083: Cannot open include file: 'dxtrans.h': No such file or directory
解决:
安装DX ......
总记录数:2015; 总页数:336; 每页6 条; 首页 上一页 [38] [39] [40] [41] 42 [43] [44] [45] [46] [47]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号