当前位置:七七学习网文档大全求职指南求职笔试面试笔试题目C/C++笔试题目常见题目» 正文

C/C++笔试题目常见题目

[10-10 21:21:19]   来源:http://www.77xue.com  笔试题目   阅读:8150
概要:C++引用C函数例子工程中包含的三个文件的源代码如下:/* c语言头文件:cExample.h */#ifndef C_EXAMPLE_H#define C_EXAMPLE_Hextern int add(int x,int y);#endif/* c语言实现文件:cExample.c */#i nclude "cExample.h"int add( int x, int y ){return x + y;}// c++实现文件,调用add:cppFile.cppextern "C"{#i nclude "cExample.h"}int main(int argc, char* argv[]){add(2,3);return 0;}如果C++调用一个C语言编写的.DLL时,当包括.DLL的头文件或声明接口函数时,应加extern "C" {}。(2)在C中引用C++语言中的函数和变量时,C++的头文件需添加e
C/C++笔试题目常见题目,标签:驾照笔试题目,腾讯笔试题目,http://www.77xue.com

C++引用C函数例子工程中包含的三个文件的源代码如下:

/* c语言头文件:cExample.h */
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
extern int add(int x,int y);
#endif


/* c语言实现文件:cExample.c */
#i nclude "cExample.h"
int add( int x, int y )
{
return x + y;
}


// c++实现文件,调用add:cppFile.cpp
extern "C"
{
#i nclude "cExample.h"
}
int main(int argc, char* argv[])
{
add(2,3);
return 0;
}

如果C++调用一个C语言编写的.DLL时,当包括.DLL的头文件或声明接口函数时,应加extern "C" { }

(2)在C中引用C++语言中的函数和变量时,C++的头文件需添加extern "C",但是在C语言中不能直接

引用声明了extern
"C"的该头文件,应该仅将C文件中将C++中定义的extern "C"函数声明为extern类型。

C引用C++函数例子工程中包含的三个文件的源代码如下:

//C++头文件 cppExample.h
#ifndef CPP_EXAMPLE_H
#define CPP_EXAMPLE_H
extern "C" int add( int x, int y );
#endif


//C++实现文件 cppExample.cpp
#i nclude "cppExample.h"
int add( int x, int y )
{
return x + y;
}


/* C实现文件 cFile.c
/* 这样会编译出错:#i nclude "cExample.h" */
extern int add( int x, int y );
int main( int argc, char* argv[] )
{
add( 2, 3 );
return 0;
}

15题目的解答请参考《C++中extern “C”含义》

16. 关联、聚合(Aggregation)以及组合(Composition)的区别?

上一页  [1] [2] [3] [4] [5] [6] 


Tag:笔试题目驾照笔试题目,腾讯笔试题目求职指南 - 求职笔试面试 - 笔试题目
联系我们 | 网站地图 | 范文大全 | 管理知识 | 教学教育 | 作文大全 | 语句好词
Copyright http://www.77xue.com--(七七学习网) All Right Reserved.
1 2 3 4 5 6 7 8 9 10