EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

C++ Commands

Home » Software Development » Software Development Tutorials » C ++ Programming Tutorial » C++ Commands

C++ Commands

Introduction to C++ Commands

C++ is an object-oriented language which was developed by Bjarne Stroustrup. It is a middle level; language which supports both high level and low-level language features. It is considered to be a superset of C and which supports all features of C language. It provides all object-oriented programming features like encapsulation, data hiding, inheritance, and polymorphism. It also has all standard libraries which act as the building block. Let us have a look at the basics and slowly move towards the advanced functions that C++ Command provides.

Basic C++ Commands

The basic commands are as follows.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. #define

This C++ Command can be used to substitute a particular value throughout the file in which it is located. This helps the compiler to go through the entire file and replaces the name of that macro which was created with the value which was defined. The replacement of this string stops at the end of the line.

#define

2. #error

This Command helps in displaying the error message which is defined and indicates the compiler to stop when this command is encountered. When the compiler comes across this command then the compiler displays the line number and message which is mentioned. This helps the programmer in debugging easily.

#error

3. #include

This includes Command helps in including the mentioned files in the code and making use of those. It can be used in two ways:

  • #include <filename>
  • #include “filename”

When angular brackets are used when a file needs to search or include through the standard library directories. When there are quotes specified then it indicates that this filename needs to be searched in the current directory.

#include

4. #pragma

By making use of this C++ command the programmer has the capability to let the compiler know of what different things are to be done. #pragma is usually implementation specific and its use can vary from one compiler to another. There are different options which can be used and one can be to trace the program execution.

Popular Course in this category
C++ Training (4 Courses, 5 Projects, 4 Quizzes)4 Online Courses | 5 Hands-on Projects | 37+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions
4.5 (4,890 ratings)
Course Price

View Course

Related Courses
Java Training (40 Courses, 29 Projects, 4 Quizzes)C Programming Training (3 Courses, 5 Project)

#pragma

5. #line

This C++ Command is used to change the value of __LINE__ and __FILE__ variables. These variables display the current file and also the line from which it is being read.

#line

6. #if

This Command helps in specifying conditions that are to be followed. It enables the user to simply apply logic control and if the condition is true then the code will immediately follow the command that will be compiled.

#if

7. #ifdef

This C++ Command is useful to check if a macro has been defined by #define statement or not. If it is already defined hen it executes the next statement that follows.

#ifDef

8. Cout

When a user wants to print some text or value of any variable that was defined previously then cout is used. It displays all values on the screen.

C++ Cout

9. Cin

In order to accept the value from the user and assign it to a particular variable, the developer must make use of cin variable. Any value can be accepted from the user and assigned to the variable of any data type that is created.

C++ cin

10. __FILE__

This variable helps in representing the current file that is being processed. It can be defined and use in the entire code and used.

C++ File

Intermediate C++ Commands

Following are the C++ commands which should be understood on an intermediate level.

1. Variable definition

A variable can be defined and lets the compiler know about where to create a variable. It also lets the compiler know how much storage is required. This definition needs a specific data type and also can contain a list of one or more variables which can follow the data type. The data type can be char, int, float, double, bool, etc.

2. Lvalue and Rvalue

The value expressions can be referred to any memory location which is called ‘lvalue’. It can appear on either left hand or right-hand side of the assignment. Rvalue is used when the data value stored at an address in the memory. It cannot have a value which can be assigned to it and it will appear on the right-hand side of the assignment.

3. Scope of Variables

The scope of variables can be either local or global. If the scope is local then it is accessible only in the function or block where the variables are defined. If the variables are defined outside all functions then they are global and can be accessed anywhere in the code.

4. Literals

Literals can be defined as the values which a program cannot alter. These can be constants which can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings, and Boolean Values.

5. Modifiers

A modifier can be used to change the meaning of the base data type and use it more precisely in different situations. The data modifiers are: signed, unsigned, long and short. These can be applied to integer base types.

6. Qualifiers

Qualifiers provide extra information regarding the variables which they precede. C++ provides three of these. Namely, these are const, volatile and restrict.

7. Storage class

This defines the scope and lifetime of variables that are present within a function. The storage classes that are provided by C++ are auto, register, static, extern and mutable.

8. Operators

This C++ Command provides all operators which are supported by C. to name a few, it supports Arithmetic Operators, Relational Operators, Logical Operators, Bitwise Operators, Assignment Operators, and Misc Operators.

9. Loops

In order to perform tasks that are performed repeatedly C++ has provided looping functions. These help in performing a set of instructions repeatedly until a specific condition is met. These loops are while, for, do..while and nested loops.

10. Arrays

An array is a data structure which is used to store a fixed-size sequential collection of elements which belong to the same type. An array stores a collection of data and is used as variables of the same type.

Advanced C++ Commands

Following is the advanced commands mentioned below.

1. C++ Files

To work with files, C++ provides the fstream library. It has three new data types – of stream, stream, and fstream. Using these it can be specified in the data type is output file stream, input file stream or any file stream respectively

2. Exception Handling

In order to handle the errors that occur at run time, C++ provides exception handling mechanism. It has tried, catch and throw blocks. Using these all exceptions that occurred can be handled.

Tips and Tricks

  • Do not get confused between the assignment operator (=) and for equality operator (==).
  • Make use of ‘using’ statement when you are working with smaller programs.
  • Do not make use of global variables except for communication between functions
  • Make use of Local variables with for statement
  • Make as much use of classes and objects as possible.

Conclusion

Hence using C++ Command is very beneficial as it is an object-oriented language. It helps in inheritance and as a result, reusing of code. C++ provides all functions of C along with these functionalities. It is very important to learn C++ Command as a base for learning other object-oriented languages.

Recommended Articles

This has been a guide to C++ Commands. Here we have discussed concept, basic, intermediate as well as advanced C++ Commands along with tips and tricks. You may also look at the following article to learn more –

  1. Tableau Commands
  2. HBase Commands
  3. MongoDB Commands
  4. Pig Commands

C++ Training (4 Courses, 3 Projects, 4 Quizzes)

4 Online Courses

5 Hands-on Projects

37+ Hours

Verifiable Certificate of Completion

Lifetime Access

4 Quizzes with Solutions

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
C plus plus Programming Tutorial
  • Basic
    • Introduction To C++
    • What is C++
    • Features of C++
    • Applications of C++
    • Best C++ Compiler
    • C++ Data Types
    • C++ Double
    • C++ unsigned int
    • User Defined Data Types in C++
    • Variables in C++
    • C++ Keywords
    • Pointers in C++
    • C++ Void Pointer
    • Function Pointer in C++
    • Iterator in C++
    • C++ Commands
    • Object in C++
    • C++ Literals
    • C++ Reference
    • C++ Undefined Reference
    • String in C++
    • C++ Programming Language (Basics)
    • C++ Identifiers
    • C++ Header Files
    • Type Casting in C++
    • C++ Formatter
  • Operators
    • C++ Operators
    • Arithmetic Operators in C++
    • Assignment Operators in C++
    • Bitwise Operators in C++
    • Relational Operators in C++
    • Boolean Operators in C++
    • Unary Operators in C++
    • C++ Operator[]
    • Operator Precedence in C++
    • C++ operator=()
  • Control Statements
    • Control Statement in C++
    • if else Statement in C++
    • Else If in C++
    • Nested if in C++
    • Continue Statement in C++
    • Break Statement in C++
    • Switch Statement in C++
    • goto Statement in C++
    • C++ Struct
    • Loops in C++
    • Do While Loop in C++
    • Nested Loop in C++
  • Functions
    • C++ String Functions
    • Math Functions in C++
    • Friend Function in C++
    • Recursive Function in C++
    • Virtual Functions in C++
    • strcat() in C++
    • swap() in C++
    • strcmp() in C++
    • ceil function in C++
    • C++ begin()
    • size() in C++
    • C++ test()
    • C++ any()
    • C++ Bitset
    • C++ find()
    • C++?Aggregation
    • C++?String append
    • C++ String Copy
    • C++ end()
    • C++ endl
    • C++ push_back
    • C++ shuffle()
    • malloc() in C++
    • C++ reserve()
    • C++ unique()
    • C++ sort()
    • C++ find_if()
    • Reflection in C++
    • C++ replace()
    • C++ search()
    • C++ Memset
    • C++ size_t
    • C++ Substring
    • C++ Max
    • C++ absolute value
    • C++ memcpy
    • C++ wchar_t
    • C++ free()
    • C++ sizeof()
    • C++ Move Semantics
  • Array
    • Arrays in C++
    • 2D Arrays in C++
    • 3D Arrays in C++
    • Multi-Dimensional Arrays in C++
    • C++ Array Functions
    • String Array in C++
    • C++ Length of Array
    • C++ arraylist
  • Constuctor and Destructor
    • Constructor and Destructor in C++
    • Constructor in C++
    • Destructor in C++
    • Copy Constructor in C++
    • Parameterized Constructor in C++
  • Overloading and overriding
    • Overloading and Overriding in C++
    • Overloading in C++
    • Overriding in C++
    • Function Overloading in C++
    • Function Overriding in C++
    • Method Overloading in C++
  • Inhertiance
    • Types of Inheritance in C++
    • Single Inheritance in C++
    • Multiple Inheritance in C++
    • Hierarchical Inheritance in C++
    • Multilevel Inheritance in C++
    • Hybrid Inheritance in C++
  • Sorting
    • Sorting in C++ 
    • Heap Sort in C++
    • C++ Vector Sort
    • Insertion Sort in C++
    • Selection Sort in C++
  • Advanced
    • C++ namespace
    • Encapsulation in C++
    • Access Modifiers in C++
    • Abstract Class in C++
    • C++ Class and Object
    • What is Template Class in C++?
    • C++ Algorithm
    • Data Structures and Algorithms C++
    • C++ Garbage Collection
    • Virtual Keyword in C++
    • Access Specifiers in C++
    • Storage Class in C++
    • Call by Value in C++
    • Multimap in C++
    • C++ Multiset
    • C++ Lambda Expressions
    • Stack in C++
    • C++ Static
    • C++ static_cast
    • Deque in C++
    • C++ Vector Functions
    • C++ 2D Vector
    • C++ List
    • C++ Mutable
    • Enum in C++
    • Abstraction in C++
    • Signal in C++
    • C++ Queue
    • Priority Queue in C++
    • Regular Expressions in C++
    • C++ Hash Table
    • File Handling in C++
    • C++ Stream
    • ifstream in C++
    • C++ ofstream
    • C++ fstream
    • C++ Read File
    • C++ iomanip
    • Macros in C++
    • Templates in C++
    • C++ setprecision
    • C++ Int to String
    • C++ thread( )
    • C++ Thread Pool
    • C++ thread_local
  • Programs
    • Patterns in C++
    • Star Patterns In c++
    • Swapping in C++
    • Reverse Number in C++
    • Palindrome Program in C++
    • Palindrome in C++
    • Factorial Program in C++
    • Fibonacci Series in C++
    • Square Root in C++
    • Random Number Generator in C++
    • Prime Number in C++
    • Leap Year Program in C++
    • Anagram in C++
    • Armstrong Number in C++
    • Reverse String in C++
    • Socket Programming in C++
    • Matrix Multiplication in C++
    • C++ using vs typedef
    • C++ vector vs list
    • C++ vector vs array
  • Interview question
    • C++ Interview Questions
    • Multithreading Interview Questions C++

Related Courses

C++ Training Course

Java Training Course

C Programming Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C++ Training (4 Courses, 3 Projects, 4 Quizzes) Learn More