C/C++题集
转自: http://hi.baidu.com/elliott_hdu/blog/item/411421dd5bf8dfe977c63876.html
1.下列程序的输出结果为:(B)
#include<iostream.h>
void main()
{
char* a[ ] = { "hello", "the", "world"};
char** pa = a;
pa++;
cout<<”*pa<<endl;
}
A) theworld B) the C) ello D) ellotheworld
2. 已知二叉树后序遍历序列是bfegcda,中序遍历序列是badefcg,它的前序遍历序列是:(B)
A) abcdefg B) abdcefg C) adbcfeg D) abecdfg
【注】抓住后序遍历最后遍历root的特点,将二叉树分为该root的左右子树。
后中->前:抓住后序遍历的特点,从后开始,每个节点为剩下树的根;
前中->后:从前开始,每个节点为剩下树的根
3. 栈和队列的共同特点是:(C)
A) 都是先进先出 B) 都是先进后出
C) 只允许在短点处插入和删除元素 D) 没有共同点
4. 下面程序的运行结果为:(A)
#include <iostream.h>
void main()
{
int a, x;
for(a = 0, x = 0; a<=1 && !x++; a++)
{
a++;
}
cout<< a << x <<endl;
}
A) 21 B) 22 C) 32 D) 41
【注】循环的执行顺序
5. 下列选项,不正确的是:(B) while后没有分号
A) for(int a=1; a<=10; a++);
B) int a=1;
do
{
&nbs
相关文档:
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setfillpatterne函数
setfillpatterne函数的功能是选择用户定义的填充模式,其用法为:void far setfillpattern(char far *upattern, int ......
某些场合,如游戏开发,工程计算中,可能需要计算反三角函数,下面是计算反正切三角函数的c源代码实例:
atan_self(double x)
{
//atan(x)=x-x^3/3+x^5/5-x^7/7+.....(-1<x<1)
//return:[-pi/2,pi/2]
double mult,sum,xx;
sum=0;
if(x==1){
return pi/4;
}
if(x==-1){
return -pi/4;
}
((x&g ......
函数名: abort
功 能: 异常终止一个进程
用 法: void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Calling abort()\n");
abort();
return 0; /* This is never reached */
}
......
题目:输入三个字符串a,b和c,将a中b的第一次出现替换为c。
代码:
#include <iostream.h>
#include <string.h>
/*字符串替换,第一个参数为原串,第二个参数为要匹配的子串
第三个参数为要替换的第一个子串中包含第二个子串的部分*/
char *strReplace(char *str1,char *str2,char *str3);
void main() ......
#include <stdio.h>
int main()
{
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p + 1 );
str[2] = p[1] + 3;
str[3] = p[0] + ( str[2] - str[1] );
printf ( "%s\n", str[0] );
printf ( ......