文章分类 - C++
摘要:// EunmNtdll.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include /********************************************************************************* 函 数 名 : GetServiceID* 功能描述 : 取得SSDT函数索引号* 参数列表 : * 说 明 : * 返回结果 : 如果成功返回索引号,失败返回-1**************************************************************
阅读全文
摘要:int my_atoi(char* p){ bool neg_flag = false;// 符号标记 int res = 0;// 结果 if(p[0] == '+' || p[0] == '-') neg_flag = (*p++ != '+'); while(isdigit(*p)) res = res*10 + (*p++ - '0'); return neg_flag ?0 -res : res;}int my_atoi1(char* p){ bool neg_flag = false;// 符号标记 int res =
阅读全文
摘要:比如:e.cppint a();//相当于extern int a,全局的,意思就是 这个函数可能在其他文件或者在本文件中定义的,int a(){return 0;}编译器在编译的时候,会对项目中的每个cpp编译成一个obj,然后在通过所有的obj连接成一个.exe程序那么.h有什么用呢?比如:一xx.h:extern a = 1;xx.cppinclude "xx.h"在这个cpp中,他相当于把xx.h中的内容给拷贝到这里来.一个CPP文件中的所有函数和所有的变量都是全局的,所以得在.h中如果要引用一个全局变量的话,需要加上extern,表示到其他地方去找这个变量
阅读全文
摘要:C++的静态局部变量虽然是局部的,但是具有全局静态变量的生命期, 也就是说整个应用程序退出后,她才会被释放内存
阅读全文
摘要:---恢复内容开始---char[10] ,char[] 其实是一样的char[10] a="sdg";//那么他的sizeof(a)=10,因为数组长度是10个字节,strlen(a)=4.因为"sdg"其实等于={'s','d','g','\0'}char a[] = "sdg";//sizeof(a)=4,因为他占了4个字节char* a= "dsfsd";//sizeof(a)=4,因为他是取的char*类型的指针,指针都是占4个字节,strl
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"class Student{public://默认为private访问 int age; int getAge(){ return this->age; } void setAge(int age){ this->age = age; }};//这里要打分号int _tmain(int argc, _TCHAR* argv[]){ Student s;//这个就是实例化了一个对象 s.setAge(12); int a ...
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"template x xxx(x a,x1 a1){ //相当于方法参数会把template里面的参数给替换掉, x abc = 123;return a;}int _tmain(int argc, _TCHAR* argv[]){int a = xxx(1,2);printf("%d",a);getchar();}
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。////重载函数,函数重载与返回值无关#include "stdafx.h"void xxx(int a,int b){a=123;b=321;}int xxx(int a){a=123;return 0;}int _tmain(int argc, _TCHAR* argv[]){xxx(1,2);xxx(1);}
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"void xxx(int a,int b=33){a=123;b=321;}int _tmain(int argc, _TCHAR* argv[]){ int a=1; int b=0; try{ printf("%d",a/0); }catch(...){//处理所有的异常 }}
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"void xxx(int a=33,int b=33){a=123;b=321;}int _tmain(int argc, _TCHAR* argv[]){ xxx(); return 0;}
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"void xxx(int &a,int &b){a=123;b=321;}int _tmain(int argc, _TCHAR* argv[]){ int i=20; int &j=i; //引用i变量的地址,也就是把他的栈中的地址交给他 //下面2行是错误的 //int &j; //j=i j=30; printf("i=%d,j=%d",i,j); printf("\n"); printf(&quo
阅读全文
摘要:// C++练习.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){//1.动态分配内存 int* p; p = new int;//new关键字,动态分配内存,其实new就是调用malloc实现的 delete p;//释放内存 return 0;//2.单维数组分配内存和多维数组 int *p1; p1 = new p1[15]; delete []p1; int (*p2)[3]; p1 = new p1[15][3]; d...
阅读全文

浙公网安备 33010602011771号