Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

ما الفرق بين تعريف دالة تأخذ باراميتر نوعه مؤشر(*) لـ struct و تعريف دالة تأخذ باراميتر نوعه عنوان(&) لـ struct؟

في درس النوع struct، فقرة الأمثلة الشاملة و في المثال الثالث تحديداً.

ما الفرق بين ما قمنا به في المثال و بين تعريف دالة تأخذ باراميتر نوعه عنوان (&) لـ struct على هذا الشكل:

#include<bits/stdc++.h>
using namespace std;
struct Book {
string title;
string author;
double price;
int numberOfPages;
};
void printInfo(struct Book& book)
{
cout << "Title: " << book.title << "\n";
cout << "Author: " << book.author << "\n";
cout << "Price: " << book.price << "$\n";
cout << "Number of pages: " << book.numberOfPages << "\n";
}
int main()
{
struct Book book;
book.title = "C++ for beginners";
book.author = "Mhamad Harmush";
book.price = 9.99;
book.numberOfPages = 420;
printInfo(book);
return 0;
}
#include<bits/stdc++.h> using namespace std; struct Book { string title; string author; double price; int numberOfPages; }; void printInfo(struct Book& book) { cout << "Title: " << book.title << "\n"; cout << "Author: " << book.author << "\n"; cout << "Price: " << book.price << "$\n"; cout << "Number of pages: " << book.numberOfPages << "\n"; } int main() { struct Book book; book.title = "C++ for beginners"; book.author = "Mhamad Harmush"; book.price = 9.99; book.numberOfPages = 420; printInfo(book); return 0; }

تعليقات 1

أضف تعليق

يجب تسجيل الدخول حتى تتمكن من إضافة تعليق أو رد.