Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Τα σχόλια στη γλώσσα C++ είναι επεξηγηματικά κείμενα που προσθέτουν οι προγραμματιστές μέσα στον κώδικα για να περιγράψουν τη λειτουργία και τον σκοπό του. Τα σχόλια βοηθούν στην κατανόηση του κώδικα από άλλους προγραμματιστές ή από τον ίδιο τον προγραμματιστή σε μεταγενέστερο χρόνο.

Στη γλώσσα C++, υπάρχουν δύο τρόποι για την προσθήκη σχολίων:

  1. Ενιαία γραμμή σχολίου: Ένα ενιαίο γραμμής σχόλιο ξεκινά με διπλή κάθετο (//) και περιέχει κείμενο μέχρι το τέλος της γραμμής. Ό,τι βρίσκεται μετά το // θεωρείται σχόλιο και αγνοείται από τον μεταγλωττιστή.

Παράδειγμα:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
int x = 5; // Αυτή η μεταβλητή αποθηκεύει την τιμή 5
int x = 5; // Αυτή η μεταβλητή αποθηκεύει την τιμή 5
int x = 5; // Αυτή η μεταβλητή αποθηκεύει την τιμή 5
  1. Πολλαπλές γραμμές σχολίων: Ένα πολλαπλών γραμμών σχόλιο ξεκινά με /* και τελειώνει με */ και μπορεί να περιέχει κείμενο σε πολλαπλές γραμμές.

Παράδειγμα:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*
Αυτή είναι μια συνάρτηση που εκτυπώνει
το κείμενο "Hello, World!" στην οθόνη
*/
void printHello() {
cout << "Hello, World!" << endl;
}
/* Αυτή είναι μια συνάρτηση που εκτυπώνει το κείμενο "Hello, World!" στην οθόνη */ void printHello() { cout << "Hello, World!" << endl; }
/*
Αυτή είναι μια συνάρτηση που εκτυπώνει
το κείμενο "Hello, World!" στην οθόνη
*/
void printHello() {
    cout << "Hello, World!" << endl;
}

Τα σχόλια είναι χρήσιμα για την τεκμηρίωση του κώδικα, την ευκολότερη ανάγνωση και κατανόηση του από άλλους προγραμματιστές, καθώς και για την αποσφαλμάτωση και την εντοπισμό πιθανών σφαλμάτων.

21 Ιουνίου, 2023
top
error: Content is protected !!
Μετάβαση σε γραμμή εργαλείων