Hello World-Programm in C++ mit Code-Erklärung (2024)

Hello World-Programm in C++

Das „Hello World“-Programm ist der erste, aber wichtigste Schritt zum Erlernen einer Programmiersprache und sicherlich das einfachste Programm, das Sie mit jeder Programmiersprache lernen werden. Sie müssen lediglich die Meldung „Hello World“ auf dem Ausgabebildschirm anzeigen.

Schauen wir uns nun den C++ Hello World Code an:

Schritt 1) Auf der Konfigurationsseite. Wählen Sie die Option „Cache jetzt erstellen“.

Sie sollten einen Bildschirm wie diesen sehen

In einigen Computern und operaBei der Installation von Systemen wird gefragt, ob alle Bibliotheken einbezogen werden sollen. Wenn die Option ausgewählt ist, werden alle Bibliotheken installiert.

Schritt 2) Erstellen Sie eine neue Quelldatei.
Sobald das Programm geöffnet ist, müssen Sie eine neue Quelldatei erstellen, damit Sie mit dem Schreiben Ihrer ersten beginnen können C ++ - Programm. Wählen Sie dazu Datei > Neu > Quelldatei. Der Pfad ist in der folgenden Abbildung dargestellt.

Dadurch wird ein Bereich geöffnet, in dem Sie Ihren Code eingeben können.

Schritt 3) Jetzt können Sie den C++-Code schreiben. Danach können Sie den C++-Code wie im Bild unten gezeigt schreiben:

C++-Codebeispiel:

#include<iostream> using namespace std; int main() { cout<<"Hello World"<<endl; return 0; } 

Schritt 4) Kompilieren Sie Ihren Code. Klicken Sie in diesem Schritt auf Ausführen -> Kompilieren und ausführen

Schritt 5) Speicher die Datei. Nach dem Speichern sollten Sie einen schwarzen Bildschirm mit der Meldung „Hello World“ sehen.

Output

Ihr erstes Programm: C++ „Hello World!“ Erläuterung

C++ ist eine kompilierte Sprache. Der Quellcode wird in Objektdateien kompiliert. Objektdateien werden dann von einem Linker kombiniert, wodurch ein ausführbares Programm entsteht.

Ein Produktions-C++ besteht aus vielen Quellcodedateien (normalerweise als Quelldateien bezeichnet).

  • Geschweifte Klammern, {}, drücken die Gruppierung in C++ aus. Sie geben hier den Anfang und das Ende des Funktionskörpers an.
  • Jedes C++-Programm hat genau eine globale Funktion namens main(). Das Programm beginnt mit der Ausführung dieser Funktion. Von main() wird ein int-Wert zurückgegeben, den es an das System übergibt.' Wenn kein Wert zurückgegeben wird, erhält das System den Wert 0, was den erfolgreichen Abschluss anzeigt. Ein Wert ungleich Null aus der Funktion main() weist auf einen Fehler hin.

Erläuterung des C++ Hello World-Programmcodes

Codezeile 1: Die erste Zeile ist #include . Es weist den Compiler an, die Standard-Stream-I/O-Bibliothek einzubinden. Ohne diese Header-Einbindung würde der Ausdruck nicht kompiliert werden.

std::cout << "Hello, World"<<endl

Codezeile 4: int main(). Dies ist die Hauptfunktion des Programms. Funktionen werden durch die Klammern() gekennzeichnet. Vor der Hauptfunktion steht „int“. Das bedeutet, dass die Hauptfunktion eine Ganzzahl an die Funktion oder den Prozess zurückgibt, die sie aufgerufen hat.

Machen Sie sich darüber vorerst keine Sorgen, beachten Sie einfach, dass das Programm vor dem Ende eine Ganzzahl zurückgeben muss. Die geschweiften Klammern { und } enthalten den Code innerhalb einer Funktion. Das Programm endet am Ende der mit } bezeichneten Hauptfunktion.

Codezeile 6: Die operator << schreibt sein zweites Argument auf sein erstes. In diesem Fall wird das String-Literal „Hello, World!“ verwendet. wird in den Standardausgabestream std::cout geschrieben.

(Note: Ein String-Literal ist eine Folge von Zeichen, umgeben von double Zitate. endl fügt ein Newline-Zeichen in derselben Zeile ein)

Codezeile 7: 0 zurückgeben; Dies ist der letzte Befehl in der Hauptfunktion, die Return-Anweisung. Ihr Zweck besteht lediglich darin, einen Wert an die Funktion oder den Prozess zurückzugeben, die als Hauptfunktion bezeichnet wird. Machen Sie sich darüber keine Sorgen, abgesehen davon, dass es für das „int“ vor der Hauptfunktionsdefinition erforderlich ist. Die Hauptfunktion sollte eine Null zurückgeben, was bedeutet, dass das Programm erfolgreich ausgeführt und beendet wurde.

cout<<"Hello World"<<endl;

Hinweis: Cout ist ein Stream, der an den angegebenen Stream ausgibt. Dies ist standardmäßig der Standardausgabestream. Cout kommt in Programmen sehr häufig vor, da das ultimative Motiv in jedem Programm darin besteht, eine Ausgabe zu liefern. endl; stellt das Ende von Anweisungen in C++ dar. Das Semikolon in C++ trennt verschiedene Anweisungen und muss in C++ am Ende von Anweisungen stehen.

Zusammenfassung

  • Das „Hello World“-Programm ist der erste Schritt zum Lernen Programmiersprache.
  • Nach der Installation eines C ++ - Compiler und einem Texteditor Ihrer Wahl können Sie Ihr erstes grundlegendes C++-Programm ausführen.
  • Die erste Zeile ist #include . Es weist den Compiler an, die Standard-Stream-I/O-Bibliothek einzubinden.
  • : int main(). Dies ist die Hauptfunktion des Programms.
  • Die operator << schreibt sein zweites Argument auf sein erstes.
  • Rückgabe 0; ist der letzte Befehl in der Hauptfunktion, der Return-Anweisung.
  • : Cout ist ein Stream, der den angegebenen Stream ausgibt.

Du magst vielleicht:

  • C++-Polymorphismus mit Beispiel
  • C + + OperaTor-Überladung mit Beispielen
  • So laden Sie die C++-IDE herunter und installieren sie auf Windows
  • C++-Tutorial für Anfänger: Erlernen Sie die Grundlagen der Programmierung in 7 Tagen
  • Unterschied zwischen Struktur und Klasse in C++
  • C++-Tutorial-PDF für Anfänger (Jetzt herunterladen)
  • Statische Memberfunktion in C++ (Beispiele)
Hello World-Programm in C++ mit Code-Erklärung (2024)

FAQs

What is a correct syntax to output Hello World in C++? ›

int main() { cout << "Hello World!"; return 0; }

How to start a program in C++? ›

Begin your 1st C++ Program
  1. Open any text editor or IDE and create a new file with any name with a .cpp extension. e.g. helloworld.cpp.
  2. Open the file and enter the below code in the C++ Compiler: #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; return 0; } ...
  3. Compile and run the code.
May 21, 2024

How to run C++ code? ›

Compile and Execute C++ Program
  1. Open a text editor and add the code as above.
  2. Save the file as: hello.cpp.
  3. Open a command prompt and go to the directory where you saved the file.
  4. Type 'g++ hello. cpp' and press enter to compile your code. ...
  5. Now, type 'a. ...
  6. You will be able to see ' Hello World ' printed on the window.

Can HackerRank detect cheating? ›

The proctoring mechanism automatically detects if a candidate switches their webcam during an ongoing test. This feature helps recruiters and hiring managers identify potential suspicious activity and allows for further investigation into why the webcam was changed mid-test.

Does HackerRank show answers? ›

The candidate's answer will be shown on the report page for the whiteboard questions. You can evaluate it and give a score.

How to code Hello World? ›

Basic example: Creating and running “Hello World”
  1. Create the following C program and name the source file hello.c : #include <stdio.h> int main(void) { printf("Hello World!\n"); return 0; }
  2. Compile the program: ...
  3. Run the program by entering the following command: ./hello.

What is C++ programming with an example? ›

C++ (or “C-plus-plus”) is a generic programming language for building software. It's an object-oriented language. In other words, it emphasizes using data fields with unique attributes (a.k.a. objects) rather than logic or functions. A common example of an object is a user account on a website.

Can I start C++ as a beginner? ›

Yes, you can learn C++ as a beginner, but it will take longer than if you already have a firm grasp of programming. If you have never programmed before, look for a C++ course that is designed with beginners in mind.

Where can I write C++ code? ›

An IDE (Integrated Development Environment) is used to edit AND compile the code. Popular IDE's include Code::Blocks, Eclipse, and Visual Studio. These are all free, and they can be used to both edit and debug C++ code. Note: Web-based IDE's can work as well, but functionality is limited.

How to learn C++ coding? ›

These tutorials will provide you with a solid foundation in C++ and prepare you you for the next step in your career.
  1. Introduction to C++ Getting Started With C++ ...
  2. C++ Fundamentals. ...
  3. Flow Control. ...
  4. Functions. ...
  5. Arrays and Strings. ...
  6. Pointers and References. ...
  7. Structure and Enumerations. ...
  8. Object Oriented Programming.

How should I practice C++ for beginners? ›

C++ Basic Exercises
  1. Write a program in C++ to find Size of fundamental data types. ...
  2. Write a program in C++ to print the sum of two numbers using variables. ...
  3. Write a program in C++ to check the upper and lower limits of integer. ...
  4. Write a program in C++ to check whether the primitive values crossing the limits or not.

How can I test my C++ code? ›

C and C++ code can be easily tested with TPT. Testing C or C++ code is possible for module and integration tests. Every piece of C/C++ code — small, big, or even integrated SW builds — can be tested with TPT. TPT masters your software tests and greatly simplifies creation, management, maintenance and analysis of tests.

What is a shortcut for running C++ program? ›

Turbo C++ Keyboard Shortcuts Keys:
S No.Shortcut keysAction
41.Ctrl + F9 'or' Alt + R + EnterRun code
42.Ctrl + LSearch selected String
43.Ctrl + NAdd New Line
44.Ctrl + SSave
49 more rows
Sep 18, 2023

How to print hello world in python in HackerRank solution? ›

Here is a sample line of code that can be executed in Python: print("Hello, World!") You can just as easily store a string as a variable and then print it to stdout: my_string = "Hello, World!"

How do you code Hello World? ›

Basic example: Creating and running “Hello World”
  1. Create the following C program and name the source file hello.c : #include <stdio.h> int main(void) { printf("Hello World!\n"); return 0; }
  2. Compile the program: ...
  3. Run the program by entering the following command: ./hello.

How to code python hello world? ›

Using the print() function

print("Hello World!") When you run this line of code, Python will output: Hello World!

References

Top Articles
Itinerario por Kioto: qué ver en 7 días [guía de viaje] - Espunis in Japan
Get directions & show routes - Computer
12 Rue Gotlib 21St Arrondissem*nt
Pau.blaz
How To Check Your Rust Inventory Value? 🔫
Black Swan Movie Online Free
Nail Salons Open Now Near My Location
Renfield Showtimes Near Amc Kent Station 14
Sessional Dates U Of T
Northern Whooping Crane Festival highlights conservation and collaboration in Fort Smith, N.W.T. | CBC News
Uwa Schedule
Minor Additions To The Bill Crossword
Craigslist Sfbay
Hướng Dẫn Trade Bittrex
ZQuiet Review | My Wife and I Both Tried ZQuiet for Snoring
Praxis für Psychotherapie und Coaching Rhein-Neckar
Gebrauchte New Holland T6.145 Deluxe - Landwirt.com
352-730-1982
Food Delivery Near Me Open Now Chinese
Sas Majors
Coleman Funeral Home Olive Branch Ms Obituaries
All Obituaries | Dante Jelks Funeral Home LLC. | Birmingham AL funeral home and cremation Gadsden AL funeral home and cremation
Alloyed Trident Spear
What Does FYP Mean on TikTok?
Takeaways from AP's report updating the cult massacre that claimed hundreds of lives in Kenya
Kahoot Spamming Bots
Spain
Resident Evil Netflix Wiki
Denise Frazier Leak
Phasmophobia Do As I Command Challenge
Power Outage Map National Grid
Skyward Crawford Ausable
Entourage Yearbook Login
Sodexo North Portal
Deborah Clearbranch Psychologist Georgia
Heavenly Delusion Gif
Surface Area Formulas (video lessons, examples, step-by-step solutions)
Hobby Lobby Locations Near Me
Business Banking Online | Huntington
Make An Appointment Att
New York Rangers Hfboards
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Lost Pizza Nutrition
Publix Coral Way And 147
Russia Ukraine war live: Starmer meets Biden at White House but no decision on Ukraine missiles
Best Drugstore Bronzers
Craigslist Boats Rochester
Grizzly Expiration Date 2023
Smokey's 35Th Halsted
new hampshire real estate - craigslist
Konami announces TGS 2024 lineup, schedule
Jaggers Nutrition Menu
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 5932

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.