摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 template 5 class A 6 { 7 int arr[N]; 8 public: 9 virtual void fun() 10 { 11 cout 16 {17 public:18 void fun() 19 { 20 cout *a = new C;31 a->fun();32 return... 阅读全文
posted @ 2013-11-27 16:54
虔诚的学习者
阅读(244)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class A 5 { 6 public: 7 A& operator=(const A&a) 8 { 9 cout 2 #include 3 4 using namespace std; 5 6 class Test 7 { 8 public: 9 void* operator new(size_t size);10 void operator... 阅读全文
posted @ 2013-11-27 16:44
虔诚的学习者
阅读(173)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class Base 5 { 6 public: 7 int fun() 8 { 9 cout 2 using namespace std; 3 class Base 4 { 5 protected: 6 int x; 7 public: 8 Base (int i) 9 { 10 x = i;11 }1... 阅读全文
posted @ 2013-11-27 16:35
虔诚的学习者
阅读(164)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class A 5 { 6 public: 7 void print() 8 { 9 cout 2 using namespace std; 3 4 class base 5 { 6 public: 7 virtual void show() 8 { 9 coutshow();36 cout getX();37 ... 阅读全文
posted @ 2013-11-27 16:29
虔诚的学习者
阅读(292)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ program. Difficulty Level: RookieQuestion 1 1 #include 2 using namespace std; 3 4 class A 5 { 6 int id; 7 public: 8 A (int i) 9 { 10 id = i; 11 }12 void print() 13 { 14 cout 2 using namespace std; 3 4 class A 5 { 6 ... 阅读全文
posted @ 2013-11-27 16:23
虔诚的学习者
阅读(207)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ program. 1 #include 2 using namespace std; 3 4 class A 5 { 6 // data members of A 7 public: 8 A () 9 { 10 cout a = a; 37 cout a = a;” in B’s constructor. The fourth line is printed by cout statement in B’s constructor. I... 阅读全文
posted @ 2013-11-27 16:14
虔诚的学习者
阅读(256)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 int fun(int a, int b = 1, int c =2) 5 { 6 return (a + b + c); 7 } 8 9 int main()10 {11 cout 2 using namespace std; 3 4 /* local variable is same as a member's name */ 5 class Test 6 { 7 pri... 阅读全文
posted @ 2013-11-27 16:09
虔诚的学习者
阅读(153)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class Point 5 { 6 private: 7 int x; 8 int y; 9 public:10 Point(const Point&p) 11 { 12 x = p.x; 13 y = p.y; 14 }15 void setX(int i) 16 {17 x = i;18 ... 阅读全文
posted @ 2013-11-27 16:03
虔诚的学习者
阅读(187)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 #include 3 using namespace std; 4 5 class String 6 { 7 char *p; 8 int len; 9 public:10 String(const char *a);11 };12 13 String::String(const char *a)14 {15 int length = strlen(a);16 p = new char[length +1];17... 阅读全文
posted @ 2013-11-27 15:56
虔诚的学习者
阅读(219)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 template class Pair 2 { 3 private: 4 S x; 5 T y; 6 /* ... */ 7 }; 8 9 template class Element10 {11 private:12 S x;13 /* ... */14 };15 16 int main ()17 {18 Pair , Element> p;19 return 0;20 } Output: Compiler ... 阅读全文
posted @ 2013-11-27 15:49
虔诚的学习者
阅读(210)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class Test1 5 { 6 int x; 7 public: 8 void show() 9 { 10 }11 };12 13 class Test214 {15 int x;16 public:17 virtual void show() 18 { 19 }20 };21 22 int main(void)23 {24 ... 阅读全文
posted @ 2013-11-27 15:42
虔诚的学习者
阅读(196)
评论(0)
推荐(0)
摘要:
Predict the output of following C++ programs.Question 1 1 class Test1 2 { 3 int y; 4 }; 5 6 class Test2 7 { 8 int x; 9 Test1 t1;10 public:11 operator Test1() 12 { 13 return t1; 14 }15 operator int() 16 { 17 return x; 18 }19 };20 21 void fun ( ... 阅读全文
posted @ 2013-11-27 15:36
虔诚的学习者
阅读(164)
评论(0)
推荐(0)
摘要:
Predict the output of below C++ programs.Question 1 1 #include 2 3 using namespace std; 4 5 class Test 6 { 7 int value; 8 public: 9 Test (int v = 0) 10 {11 value = v;12 }13 int getValue() 14 { 15 return value; 16 }17 };18 19 int main() 20 {21 cons... 阅读全文
posted @ 2013-11-27 15:28
虔诚的学习者
阅读(223)
评论(0)
推荐(0)
摘要:
Difficulty Level: Rookie Predict the output of below C++ programs.Question 1 1 #include 2 using namespace std; 3 4 class Test 5 { 6 int value; 7 public: 8 Test(int v); 9 };10 11 Test::Test(int v) 12 {13 value = v;14 }15 16 int main() 17 {18 Test t[100];19 return 0;20 } Outp... 阅读全文
posted @ 2013-11-27 15:23
虔诚的学习者
阅读(206)
评论(0)
推荐(0)
摘要:
Difficulty Level: Rookie Predict the output of below C++ programs. Question 1 1 #include 2 using namespace std; 3 4 int x = 10; 5 void fun() 6 { 7 int x = 2; 8 { 9 int x = 1;10 cout 2 using namespace std; 3 4 class Point 5 { 6 private: 7 int x; 8 int y; 9 publ... 阅读全文
posted @ 2013-11-27 15:17
虔诚的学习者
阅读(190)
评论(0)
推荐(0)
摘要:
Predict the output of below C++ programs. Question 1 1 #include 2 using namespace std; 3 4 class P 5 { 6 public: 7 void print() 8 { 9 cout 2 #include 3 4 using namespace std; 5 6 class Base 7 { 8 public: 9 Base()10 {11 fun(); //note: fun() is virtual12 }1... 阅读全文
posted @ 2013-11-27 15:06
虔诚的学习者
阅读(244)
评论(0)
推荐(0)
摘要:
Predict the output of below C++ programs. Question 1 1 #include 2 using namespace std; 3 4 class A 5 { 6 public: 7 A(int ii = 0) : i(ii) 8 { 9 }10 void show() 11 { 12 cout 2 using namespace std; 3 4 class base 5 { 6 int arr[10]; 7 }; 8 9 class b1: publ... 阅读全文
posted @ 2013-11-27 15:01
虔诚的学习者
阅读(151)
评论(0)
推荐(0)
摘要:
Predict the output of below C++ programs. Question 1 1 // Assume that integers take 4 bytes. 2 #include 3 4 using namespace std; 5 6 class Test 7 { 8 static int i; 9 int j;10 };11 12 int Test::i;13 14 int main()15 {16 cout 2 using namespace std; 3 4 class Base1 5 { 6 public:... 阅读全文
posted @ 2013-11-27 14:55
虔诚的学习者
阅读(195)
评论(0)
推荐(0)
摘要:
Every literal (constant) in C/C++ will have a type information associated with it. In both C and C++, numeric literals (e.g. 10) will have int as their type. It means sizeof(10) and sizeof(int) will return same value. However, character literals (e.g. ‘V’) will have different types, sizeof(‘V’... 阅读全文
posted @ 2013-11-27 14:50
虔诚的学习者
阅读(375)
评论(0)
推荐(0)
摘要:
In C++, namespaces can be nested, and resolution of namespace variables is hierarchical. For example, in the following code, namespace inner is created inside namespace outer, which is inside the global namespace. In the line “int z = x”, x refers to outer::x. If x would not have been in outer... 阅读全文
posted @ 2013-11-27 14:44
虔诚的学习者
阅读(275)
评论(0)
推荐(0)
摘要:
A nested class is a class which is declared in another enclosing class. A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules shall be obeyed. For examp... 阅读全文
posted @ 2013-11-27 14:41
虔诚的学习者
阅读(387)
评论(0)
推荐(1)
摘要:
A class declared inside a function becomes local to that function and is called Local Class in C++. For example, in the following program, Test is a local class in fun(). 1 #include 2 using namespace std; 3 4 void fun() 5 { 6 class Test // local to fun 7 { 8 /* members of Te... 阅读全文
posted @ 2013-11-27 14:34
虔诚的学习者
阅读(544)
评论(0)
推荐(0)
摘要:
Ever wondered how can you design a class in C++ which can’t be inherited. Java and C# programming languages have this feature built-in. You can use final keyword in java, sealed in C# to make a class non-extendable. Below is a mechanism using which we can achieve the same behavior in C++. It make... 阅读全文
posted @ 2013-11-27 14:21
虔诚的学习者
阅读(251)
评论(0)
推荐(0)
摘要:
C allows a void* pointer to be assigned to any pointer type without a cast, whereas C++ does not; this idiom appears often in C code using malloc memory allocation. For example, the following is valid in C but not C++:void* ptr;int *i = ptr; /* Implicit conversion from void* to int* */ or similar... 阅读全文
posted @ 2013-11-27 12:31
虔诚的学习者
阅读(222)
评论(0)
推荐(0)
摘要:
In C, it might not be possible to have function names on left side of an expression, but it’s possible in C++. 1 #include 2 using namespace std; 3 4 /* such a function will not be safe if x is non static variable of it */ 5 int &fun() 6 { 7 static int x; 8 return x; 9 } 10 11 int main... 阅读全文
posted @ 2013-11-27 12:24
虔诚的学习者
阅读(176)
评论(0)
推荐(0)
摘要:
In C, we cannot access a global variable if we have a local variable with same name, but it is possible in C++ using scope resolution operator (::). 1 #include 2 using namespace std; 3 4 int x; // Global x 5 6 int main() 7 { 8 int x = 10; // Local x 9 cout<<"Value of global x is "< 阅读全文
posted @ 2013-11-27 12:18
虔诚的学习者
阅读(300)
评论(0)
推荐(0)
摘要:
Calling an undeclared function is poor style in C (See this) and illegal in C++. So is passing arguments to a function using a declaration that doesn’t list argument types: If we save the below program in a .c file and compile it, it works without any error. But, if we save the same in a .cpp fil... 阅读全文
posted @ 2013-11-27 12:11
虔诚的学习者
阅读(332)
评论(0)
推荐(0)
浙公网安备 33010602011771号