@ 声明一个指向含有10个元素的数组的指针,其中每个元素是一个函数指针,该函数的返回值是int,参数是int*,正确的是(C)
(int *p[10])(int*)
int [10]*p(int *)
int (*(*p)[10])(int *)
int ((int *)[10])*p
@ 下述程序的输出是______。
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
@ 声明一个指向含有10个元素的数组的指针,其中每个元素是一个函数指针,该函数的返回值是int,参数是int*,正确的是(C)
(int *p[10])(int*)
int [10]*p(int *)
int (*(*p)[10])(int *)
int ((int *)[10])*p
@ 下述程序的输出是______。
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
@ 在32位cpu上选择缺省对齐的情况下,有如下结构体定义:
struct A{
unsigned a : 19;
unsigned b : 11;
unsigned c : 4;
unsigned d : 29;
char index;
};
则sizeof(struct A)的值为()
@ 已知int占4个字节,bool占1个字节,问value, condition 的值为____。
unsigned int
value = 1024;
bool condition =
*((bool *)(&value));
if (condition)
value += 1; condition = *((bool *)(&value));
if (condition)
value += 1; condition = *((bool *)(&value));
@ 有如下程序段:则程序输出:
#include <iostream>
using namespace std;
class A {
public:
~A() {
cout << "~A()";
}
};
class B{
public:
virtual ~B() {
cout << "~B()";
}
};
class C: public A, public B {
public:
~C() {
cout << "~C()";
}
};
int main() {
C * c = new C;
B * b1 = dynamic_cast<B *>(c);
A * a2 = dynamic_cast<A *>(b1);
delete a2;
}
@ 下列代码的输出是?(注:print已经声明过)
main(){
char str[]="Geneius";
print (str);
}
print(char *s){
if(*s){
print(++s);
printf("%c",*s);
}
}
@ 以下程序的输出结果是()。
void main ()
{
char arr[2][4];
strcpy (arr[0],"you");strcpy (arr[1],"me");
arr[0][3]=’&’;
printf("%s \n",arr);
}
@ 以下程序的输出结果:
using namespace std;
void print(char **str)
{
++str;
cout<<*str<<endl;
}
int main()
{
static char *arr[]={"hello", "world", "c++"};
char **ptr;
ptr=arr;
print(ptr);
return 0;
}
@ 下列程序的输出结果:编译出错
#include <iostream>
using namespace std;
class A
{
public:
void print()
{
cout << "A:print()";
}
};
class B: private A
{
public:
void print()
{
cout << "B:print()";
}
};
class C: public B
{
public:
void print()
{
A:: print();
}
};
int main()
{
C b;
b.print();
}
@ 在32位环境下,以下代码输出的是
#include<stdio.h>
class A
{
public:
A(){ printf(“A”);}
~A(){ printf(“~A”);
};
class B:public A
{
public;
B(){ printf(“B”);}
~B(){ printf(“~B”);}
};
int main()
{
A*c = new B[2];
delete[] c;
return 0;
}
@ 下列程序的输出结果为:
#include
void main()
{
char* a[ ] = { "hello", "the", "world"};
char** pa = a;
pa++;
cout<<*pa<<endl;
}
@ 执行下面程序,正确的输出是
intx=5,y=7;
void swap ()
{
int z;
z=x;
x=y;
y=z
}
int main (void)
{
int x=3,y=8;
swap();
printf ("%d,%d\n",x,y) ;
}
@ 阅读以下代码:执行结果是()
class parent
{
public:
virtual void output();
};
void parent::output()
{
printf("parent!");
}
class son : public parent
{
public:
virtual void output();
};
void son::output()
{
printf("son!");
}
son s;
memset(&s , 0 , sizeof(s));
parent& p = s;
p.output();
@ 对于下面的代码,说法正确的是____。
char* s1 = "Hello world";
char s2[] = "Hello world";
s1[2] = 'E'; // 1
s2[2] = 'E'; // 2
*(s1 + 2) = 'E'; // 3
*(s2 + 2) = 'E'; // 4
@ 如下代码段,哪种描述是正确的()
class A{/*...*/};
void f(const A**p){/*...*/}
void g(const A* const* p){/*...*/}
void k(const A*&p){/*...*/}
void main()
{
const A* ca = new A();
A*a = new A();
A**p = &a;
k(ca); //[1]
f(p); //[2]
g(p); //[3]
}
@ 下述程序有什么问题?
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void getmemory(char*p) {
p=(char *) malloc(100);
strcpy(p,"hello world");
}
int main( )
{
char *str=NULL;
getmemory(str);
printf("%s\n",str);
free(str);
return 0;
}
@ 有一个类B继承自类A,他们数据成员如下:则构造函数中,成员变量一定要通过初始化列表来初始化的是____
class A {
...
private:
int &a;
};
class B : public A {
...
private:
int a;
public:
const int b;
A c;
static const char* d;
A* e;
};
@ 下面函数的执行结果是输出
func(char para[100])
{
void *p = malloc(100);
printf("%d, %d\n", sizeof(para), sizeof(p));
}
@ 写出下列程序在X86上的运行结果
struct mybitfields
{
unsigned short a : 4;
unsigned short b : 5;
unsigned short c : 7;
} test
void main(void)
{
int i;
test.a = 2;
test.b = 3;
test.c = 0;
i = *((short *)&test);
printf("%d\n", i);
}
@ 32位机器上,有三个类A B C定义如下, 请确定sizeof(A) sizeof(B) sizeof©的大小顺序
struct A{
A() {}
~A() {}
int m1;
int m2;
};
struct B : A{
B() {}
~B() {}
int m1;
char m2;
static char m3;
};
struct C{
C() {}
virtual~C() {}
int m1;
short m2;
};
@ 已知fun(int)是类Test的公有成员函数,p是指向成员函数fun()的指针,采用( )是正确的。
p=fun
p=Test::fun()
p=fun()
p=&Test::fun
@ 下面这段代码运行时会出现什么问题?不符合预期的输出A.
class A
{
public:
void f()
{
printf("A\n");
}
};
class B: public A
{
public:
virtual void f()
{
printf("B\n");
}
};
int main()
{
A *a = new B;
a->f();
delete a;
return 0;
}
@ 有如下程序段:则程序输出是:
class A
{
public:
A()
{
printf(“0”);
}
A(int a)
{
printf(“1”);
}
A& operator=(const A& a)
{
printf(“2”);
return*this;
}
}
int main()
{
A al;
al=10;
}
@ 如下程序:该程序的执行结果
#include "stdio.h"
class Base
{
public:
Base()
{
Init();
}
virtual void Init()
{
printf("Base Init\n");
}
void func()
{
printf("Base func\n");
}
};
class Derived: public Base
{
public:
virtual void Init()
{
printf("Derived Init\n");
}
void func()
{
printf("Derived func\n");
}
};
int main()
{
Derived d;
((Base *)&d)->func();
return 0;
}
@ 针对以下代码,判断下列说法哪个是正确的(注意是地址):______。
str1和str2地址不同,P1和P2地址相同。
str1和str2地址相同,P1和P2地址相同。
str1和str2地址不同,P1和P2地址不同。
str1和str2地址相同,P1和P2地址不同。
4个地址都不相同
const char str1[]=”abc”;
const char str2[]=”abc”;
const char *p1 = “abc”;
const char *p2 = “abc”;