0% found this document useful (0 votes)
9 views8 pages

C++ Programming Language Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

C++ Programming Language Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to C++ Programming Language

C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming


language that supports procedural, object-oriented, and generic programming.

C++ is regarded as a middle-level language, as it comprises a combination of both high-level and


low-level language features.

C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey,
as an enhancement to the C language and originally named C with Classes but later it was renamed
C++ in 1983.

C++ is a superset of C, and that virtually any legal C program is a legal C++ program.

Note − A programming language is said to use static typing when type checking is performed
during compile-time as opposed to run-time.

Object-Oriented Programming

C++ fully supports object-oriented programming, including the four pillars of object-oriented
development −

Classes and Objects, Encapsulation, Data hiding, Inheritance, Polymorphism

C++ Comments

Program comments are explanatory statements that you can include in the C++ code. These
comments help anyone reading the source code. All programming languages allow for some form
of comments.

Types of C++ Comments

C++ supports two types of comments: single-line comments and multi-line comments. All
characters available inside any comment are ignored by the C++ compiler.

The types of C++ comments are explained in detail in the next sections:

1. C++ Single-line Comments

A single-line comment starts with //, extending to the end of the line. These comments can last
only till the end of the line, and the next line leads to a new comment.

Syntax

The following syntax shows how to use a single-line comment in C++:


// Text to be commented

2. C++ Multi-line Comments

Multi-line comments start with /* and end with */. Any text in between these symbols is treated as
a comment only.

Syntax

The following syntax shows how to use a multi-line comment in C++:

/* This is a comment */

/*

C++ comments can also

span multiple lines

*/

Tokens

C++ tokens are the smallest individual units of a program, that the compiler recognizes and
processes. Together, they form the syntax of C++ code, the same as combining words to form a
sentence.

C++ is the superset of C and so most constructs of C are legal in C++ with their meaning and usage
unchanged. So tokens, expressions, and data types are similar to that of C.

Followings are C++ tokens given below

Keywords

Identifiers

Constants

Variables

Operators

Punctuation
Keywords

Keywords are reserved words which have fixed meaning, and its meaning cannot be changed. The
meaning and working of these keywords are already known to the compiler. C++ has more
numbers of keyword than C, and those extra ones have special working capabilities.

List of some commonly used keywords

Control flow: if, else, switch, case, break, continue, return, goto

Data types: int, char, double, float, bool, void, long, short

Storage classes: static, extern, mutable, register, volatile

Object-oriented programming: class, struct, public, private, protected, virtual, this, friend

Other: namespace, using, typedef, const, sizeof, typeid, template, new, delete

Identifiers

Identifiers are names given to different entries such as variables, structures, and functions, classes,
objects, arrays, etc. Also, identifier names should have to be unique because these entities are used
in the execution of the program.

Identifier naming conventions

Only alphabetic characters starting with a letter (A-Z, a-z), digits (0-9), and underscores (_) are
permitted.

The first letter must be an alphabet or underscore (_) not a number.

Identifiers are case sensitive.

Reserved keywords cannot be used as an identifier's name.

Constants

Constants are like a variable, except that their value never changes during execution once defined.

There are two other different ways to define constants in C++. These are:

By using const keyword

By using #define preprocessor


Curly braces {} Define blocks of code

Square brackets [] Denote array subscripts

What is the difference between a while loop and a do-while loop?

Following are the major difference between while and do-while loop:

While Loop do-while Loop

While loop is also termed an entry-controlled The do-while loop is termed an exit
loop control loop

If the condition is not satisfied the statements Even if the condition is not satisfied the
inside the loop will not statements inside the loop will execute
execute for at least one time

Example of a do-while loop:


Example of a while loop:
do {
while(condition)
statements to be executed;
{statements to be executed;};
} while(condition or expression);

What is the difference between function overloading and operator overloading?

Following is the main difference operator overloading and function overloading:


Function Overloading Operator Overloading

It is basically defining a function in


It is basically giving practice of giving a special
numerous ways such that there are many
meaning to the existing meaning of an operator
ways to call it or in simple terms you
or in simple terms redefining the pre-redefined
have multiple versions of the same
meaning
function

Parameterized Functions are a good


Polymorphism is a good example of an operator
example of Function Overloading as just
overloading as an object of allocations class can
by changing the argument or parameter
be used and called by different classes for
of a function you make it useful for
different purposes
different purposes

Example of Function Overloading: Example of Operator Overloading:

1. int GFG(int X, int Y); 1. int GFG() = X() + Y();

2. int GFG(char X, char Y); 2. int GFG() = X() – Y();

What is the difference between C and C++?

The following table lists the major differences between C and C++:

C C++

It is a procedural programming language. It is a mixture of both procedural and object-


In simple words, it does not support classes oriented programming languages. In simple
and objects words, it supports classes and objects.
C C++

It does not support any OOPs concepts like


polymorphism, data abstraction, It supports all concepts of data
encapsulation, classes, and objects.

It does not support Function and Operator It supports Function and Operator Overloading
Overloading respectively

It is a function-driven language It is an object-driven language


What is an Operating System?

The OS is a software that manages the computer's hardware and software resources, allowing
users to interact with the computer without needing to directly control the hardware.

In other words: It acts as an intermediary between the hardware and application programs,
providing a layer of abstraction for users and applications.

What are the main functions of an OS?

 Process Management: The OS handles the creation, execution, and termination of programs
(processes).

 Memory Management: It allocates and manages the computer's memory (RAM).

 File Management: The OS organizes and manages files and directories on the storage media.

 Input/Output (I/O) Management: The OS controls the interaction between the computer and
peripheral devices.

 Security: It provides security measures to protect the system from unauthorized access and
damage.

Difference between GUI and CUI


Both GUI and CUI have their features and specific use cases. Now, let us see the key difference
between GUI and CUI below:

Features GUI CUI

The full form of GUI is Graphical User The full form of CUI is Character User
Full-Form
Interface. Interface.

It allows the user to interact with the It allows the user to interact with the
system using a visual and graphical system using keywords and
Interaction
representation of application and commands for the working of
functionalities. application and functionalities

Navigating through the components and Navigating through the components and
Navigation
functionalities is easy in GUI functionalities is not easy in CUI

The speed of task execution in GUI is The speed of task execution in CUI is
Speed
slower. fast.

GUI utilizes more memory space which is CUI utilizes less memory space
Memory obvious due to the involvement of graphics because there are no graphics and visual
and visual elements. elements.

GUI is user-friendly and easy to use


CUI is somewhat difficult to use
because the software applications and
because, in this interface, the user needs
Usage functionalities are represented using
to memorize commands for task
graphics, which is easy to understand for
execution.
new users too.

Users interact with GUI and system by Users make interactions with CUI and
Peripherals
using external peripherals such as a mouse system by typing commands with the
used
and keyboard. help of the keyboard only.

Precision GUI execute tasks with high accuracy. CUI execute tasks with low accuracy.

GUI provides a more flexible interface for CUI provides a less flexible interface for
Flexibility
the users. the users.

Common questions

Powered by AI

GUI and CUI differ primarily in interaction and usability. GUI uses visual elements like windows, icons, and buttons, providing a user-friendly experience with ease of use, especially for novice users, through intuitive visual cues. CUI, on the other hand, involves text-based command input, requiring users to memorize and type commands, making it faster yet less accessible to beginners. GUIs demand more resources due to graphics, whereas CUIs are resource-efficient but less flexible in handling complex user interactions .

C is a procedural programming language that does not support object-oriented programming (OOP) concepts like classes and objects, whereas C++ is a mixture of both procedural and object-oriented programming languages, supporting features such as classes, objects, polymorphism, data abstraction, and encapsulation. Additionally, C++ supports function and operator overloading, providing more flexibility in defining behaviors, while C does not .

C++ being a superset of C significantly benefits legacy code integration, as it allows older C programs to run under C++ compilers with minimal adjustments. This facilitates incremental code modernization and adoption of object-oriented features. However, incorporating C's procedural style into object-oriented C++ can lead to conflicts if the paradigms are not managed properly, potentially causing maintenance challenges. Careful refactoring ensures that enhancements do not disrupt legacy functionality while leveraging C++ features .

Static typing in C++ means that type checking is performed during compile-time rather than at run-time. This can lead to more efficient code execution and error detection before the program is run, as the compiler can enforce type rules and potentially optimize the generated machine code. Dynamic typing, in contrast, can lead to run-time errors and typically requires additional checks or overhead during execution .

C++ tokens form the basic building blocks of the language's syntax and structure, encompassing keywords, identifiers, constants, variables, operators, and punctuation. They are the smallest units recognized by the compiler, allowing for meaningful code parsing and compilation. Well-defined tokens enable the construction of complex expressions and statements, crucial for creating a structured and syntactically correct program, thereby ensuring seamless communication between the programmer's instructions and the compiler .

Function overloading in C++ allows multiple functions to have the same name with different parameters, enabling different operations or logic to be executed based on input type or count, thereby improving flexibility and readability. Operator overloading allows redefining the behavior of operators for user-defined types, enabling intuitive operations akin to built-in data types. Both techniques enhance program flexibility by allowing polymorphism and code reuse but must be used judiciously to avoid ambiguity and maintain clear logic .

Identifiers in C++ are names for entities such as variables and functions, and their naming conventions are critical for ensuring program functionality and avoid conflicts. Identifiers must start with a letter or an underscore, cannot be reserved keywords, and are case-sensitive. This stringent set of rules ensures that the compiler correctly interprets and manages these identifiers without clashes, enabling clear and error-free execution of the program .

Comments in C++ improve code readability and maintainability by providing explanations and context for developers, minimizing misinterpretation and assisting in debugging or updating code. They help document the purpose of code blocks or complex logic, which can be crucial during collaboration in large projects. However, excessive comments can clutter the code or, if not kept up to date, mislead other developers, potentially causing confusion if the commented information is outdated or incorrect .

While loops and do-while loops offer distinct trade-offs in C++. While loops are entry-controlled, meaning the condition is checked before the loop body executes, ideal for scenarios where initialization or no execution is necessary if the condition fails. Do-while loops are exit-controlled, guaranteeing at least one execution of the loop body. This makes do-while preferable when the logic must execute once, regardless of the condition. The choice affects control flow and behavior depending on initial and subsequent conditions .

The four pillars of object-oriented programming (OOP) in C++ — encapsulation, data hiding, inheritance, and polymorphism — are fundamental as they enable developers to create modular, reusable, and more maintainable code. Encapsulation allows bundling of data with methods that operate on the data. Data hiding ensures that internal object details are not exposed unnecessarily, enhancing security and integrity. Inheritance facilitates code reuse and the creation of hierarchical relationships between classes, while polymorphism allows methods to be used for different forms, increasing flexibility and interface consistency .

You might also like