Explain all the C++ concepts using examples.
Answer / Neeraj Chaudhary
1. Variables and Data Types: int x = 5; // integer variable
2. Functions: void printHello() { cout << "Hello, World!" << endl; }
3. Operators: int y = 7 + 3;
4. Control Structures: if (x > y) cout << x << " is greater than " << y << endl;
5. Arrays: int arr[5] = {1, 2, 3, 4, 5};
6. Loops: for (int i = 0; i < 5; ++i) {n cout << arr[i] << " ";n}
7. Pointers: int *ptr = &x;
8. Classes and Objects: class MyClass {npublic:n int value;n}; MyClass obj, obj2;
9. Inheritance: class Derived : public Base {npublic:n void myMethod() {n cout << "Derived method called" << endl; n }n};n10. Polymorphism: class Animal {npublic:n virtual void speak() = 0;n}; class Dog : public Animal {npublic:n void speak() { cout << "Woof!" << endl; }n}
| Is This Answer Correct ? | 0 Yes | 0 No |
What is Pure Virtual Function? Why and when it is used ?
Write a C++ program which will compute the volume of a sphere or a cylinder after prompting the user to type the first character for the shape name.
0 Answers An-Najah National University,
How can you find the nodes with repetetive data in a linked list?
What are the types of container classes?
What is virtual destructor? What is its use?
What are the operators in c++?
How do you print a string on the printer?
Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
What are the storage qualifiers?
Write about the stack unwinding?
Does c++ have string data type?
Explain about templates of C++.