随笔分类 - 运行结果
摘要:给出输出结果:A,编译错误B,编译成功,运行错误C,编译正常,输出10#include <iostream>using namespace std;class A{private: int value;public: A(int a) { value =a; } A ( A other) { value =other.value; } void Print() { cout<<value<<endl; }};int main(){ A a = 10; A b = a; b.Print(); system("pause"); return
阅读全文
摘要:#include <stdio.h>int main(void){int a,b,c,d;a = 3;b = 4;c = a,b;d = (a,b);printf("c = %d/n",c);printf("d = %d/n",d);return 0;}c = 3d = 4
阅读全文
摘要:float a = 1.0f;cout << (int)a << endl;cout << (int&)a << endl;cout << boolalpha << ( (int)a == (int&)a ) << endl; // 输出什么?float b = 0.0f;cout << (int)b << endl;cout << (int&)b << endl;cout << boolalpha << ( (in
阅读全文
摘要:struct CLS{int m_i;CLS( int i ) : m_i(i) {}CLS(){CLS(0);}};CLS obj;cout << obj.m_i << endl;答:不能。在默认构造函数内部再调用带参的构造函数属用户行为而非编译器行为,亦即仅执行函数调用,而不会执行其后的初始化表达式。只有在生成对象时,初始化表达式才会随相应的构造函数一起调用。
阅读全文
摘要:char str1[] = "abc";char str2[]= "abc";const char str3[] = "abc";const char str4[] = "abc";const char* str5= "abc";const char* str6= "abc";cout << boolalpha<< ( str1==str2 )<< endl; // 输出什么?cout << boolalpha<<
阅读全文
摘要:#include <iostream>using namespace std;class A{public: A(){ doSth(); } virtual void doSth(){cout<<("I am A");}};class B:public A{public: virtual void doSth(){ cout<<("I am B");}};int main(){B b;return 0;}I am A#include <iostream>using namespace std;class A
阅读全文