Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
logo
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

Hello, World!

C++ is a general purpose programming language that is free-form and compiled. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features. It provides imperative, object-oriented and generic programming features.

The overall program has a structure, but it is also important to understand the purpose of part of that structure.

Here is the code to print Hello, World! in C++

Detailed Explanation:

We’ll start from the very first line and go step by step!

The hash sign (#) signifies the start of a preprocessor command. The #include command is a specific preprocessor command that effectively copies and pastes the entire text of the file specified between the angle brackets into the source code. In this case, the file is “iostream” which is a standard file that should come with the C++ compiler. This file name is short for “input-output streams”; in short, it contains code for displaying and getting the text from the user.

The include statement allows a programmer to “include” this functionality in the program without having to literally cut and paste it into the source code every time. The iostream file is part of the C++ standard library, which provides a set of useful and commonly used functionality provided with the compiler. The “include” mechanism, however, can be used both for standard code provided by the compiler and for reusable files created by the programmer.

C++ supports the concept of namespaces. A namespace is essentially a prefix that is applied to all the names in a certain set. One way to think about namespaces is that they are like toolboxes with different useful tools. The using command tells the compiler to allow all the names in the “std” namespace to be usable without their prefix. The iostream file defines three names used in this program - cout, cin, and endl - which are all defined in the std namespace. “std” is short for “standard” since these names are defined in the standard C++ library that comes with the compiler.

Without using the std namespace, the names would have to include the prefix and be written as std::cout, std::cin, and std::endl.

The starting point of all C++ programs is the main function. This function is called by the operating system when your program is executed by the computer.

cin & cout

The name cout is short for “character output” and cin, correspondingly, is an abbreviation for “character input”.

In a typical C++ program, most function calls are of the form object.function_name(argument1, argument2).

Symbols such as << can also behave like functions, as illustrated by the use of cout above. This capability is called operator overloading.

{ }

A block of code is defined with the { } tokens. { signifies the start of a block of code, ​and } signifies the end. The { } tokens have other uses as well.

semicolons

Statements in C++ must be terminated with a semicolon.

return

The return keyword tells the program to return a value to the function int main that called this function and then to continue execution in the int main function from the point at which this function was called.

The type of the value returned by a function must match the type specified in the declaration of the function.

Now that we have learned the basics of our code. Let’s solve a example in the editor below.

Write a code to print "Hello, InterviewBit!" (without quotes) in the editor below.

Start solving Hello, World! on Interview Code Editor
Hints
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions
Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College you graduated from
College/University Name
Job Title
Job Title
Engineering Leadership
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer
Security Leadership
Database Administrator
Data Analyst
Data Engineer
Non Coder
Other
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test