الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر (Line-by-Line Code Explanation)
1. When passing an object to a function by VALUE, which special member function is automatically invoked by the compiler?
2. If a function modifies an object passed to it "by value", does the original object in the `main` function change?
1. Why is it a "Best Practice" to use `const ClassName &obj` when passing an object to a function just to read its values?
2. To return an Object from a method, what must be the return type of that method?
1. When you define an array of objects like `Student classA[50];`, which constructor is automatically called for each of the 50 elements?
2. Which of the following is a strict rule regarding `static` member functions in a class?
&): الدالة بتشتغل على الـ Object الأصلي مباشرة. مفيش نسخ ولا Copy Constructor. أسرع وأوفر في الذاكرة.const ClassName &obj ← دي أفضل طريقة في البرمجة المتقدمة. بتوفر الميموري (Reference) وبتحمي الداتا (const = Read-only).void لاسم الكلاس. بنعمل Object مؤقت (temp) جوه الدالة ونرجعه بـ return.Student arr[100]; بيشغل الـ Default Constructor 100 مرة! وبنوصل لكل عنصر بالـ Index: arr[i].function().int ClassName::count = 0;ClassName::func()). ومبتشوفش غير الـ Static Variables بس.Question: Compare between "Pass by Value" and "Pass by Reference" when passing objects to functions in C++. Discuss the role of the Copy Constructor in each case, the impact on memory, and when to use `const` with references. Also, explain how `static` data members differ from regular data members.
Q1:
Q2:
Q1: Declare a static data member called totalStudents of type int inside a class, then initialize it to 0 outside the class.
Q2: Write a function that takes an object of class Student by const reference and prints its name.
Q3: Create an array of 5 Student objects.
a) What is the output?
b) Is n2 passed by value or by reference? What's the difference?