LESSON 1 and 2 C

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

A Brief History C++ and Setting Up Codeblocks

Brief History of C++


Bjarne Stroustrupwas
 The C++ programming language has a
history going back to 1979, when Bjarne
Stroustrupwas doing work for his Ph.D.
thesis. He began work on "C with Classes",
which as the name implies was meant to be
a superset of the C language. His goal was
to add object-oriented programming into
the C language, which was and still is a
language well-respected for its portability
without sacrificing speed or low-level
functionality.
 His language included classes, basic inheritance, inlining, default function
arguments, and strong type checking in addition to all the features of the C
language. The first C with Classes compiler was called Cfront, which was derived
from a C compiler called CPre. It was a program designed to translate C with
Classes code to ordinary C.
In 1983
 the name of the language was changed from C
with Classes to C++. The ++ operator in the C
language is an operator for incrementing a
variable, which gives some insight into how
Stroustrup regarded the language. Many new
features were added around this time, the most
notable of which are virtual functions, function overloading, references with the &
symbol, the const keyword, and single-line comments using two forward slashes.
In 1985
 C++ was implemented as a commercial product. The language was not officially
standardized yet. The language was updated again in 1989 to include protected and
static members, as well as an inheritance from several classes.
In 1990
 Turbo C++ was released as a commercial product. Turbo C++ added a lot of
additional libraries which have had a considerable impact on C++'s development.
In 1998
 the C++ standards committee published the first international standard for C++
ISO/IEC 14882:1998, which is informally known as C++98. The Standard
Template Library, which began its conceptual development in 1979, was also
included. In 2003, the committee responded to multiple problems that were reported
with their 1998 standard and revised it accordingly. The changed language was
named C++03.
In mid-2011,
 the new C++ standard (C++11) was finished. The new features included Regex
support, a randomization library, a new C++ time library, atomics support, a
standard threading library, a new for loop syntax providing functionality similar to
for each loops in certain other languages, the auto keyword, new container classes,
better support for unions and array-initialization lists and variadic templates.

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 general-purpose programming language that was developed as an
enhancement of the C language to include object-oriented paradigm. It is an
imperative and a compiled 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++ 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.

Learning C++

 The most important thing while learning C++ is to focus on concepts.


 The purpose of learning a programming language is to become a better programmer; that
is, to become more effective at designing and implementing new systems and at
maintaining old ones.
 C++ supports a variety of programming styles. You can write in the style of Fortran, C,
Smalltalk, etc., in any language. Each style can achieve its aims effectively while
maintaining runtime and space efficiency.
Use of C++

 C++ is used by hundreds of thousands of programmers in essentially every application


domain.
 C++ is being highly used to write device drivers and other software that rely on direct
manipulation of hardware under realtime constraints.
 C++ is widely used for teaching and research because it is clean enough for successful
teaching of basic concepts.
 Anyone who has used either an Apple Macintosh or a PC running Windows has indirectly
used C++ because the primary user interfaces of these systems are written in C++.
Why to Learn C++
 C++ is very close to hardware, so you get a chance to work at a low level which gives you
lot of control in terms of memory management, better performance and finally a robust
software development.
 C++ programming gives you a clear understanding about Object Oriented Programming.
You will understand low level implementation of polymorphism when you will
implement virtual tables and virtual table pointers, or dynamic type identification.
 C++ is one of the every green programming languages and loved by millions of software
developers. If you are a great C++ programmer then you will never sit without work and
more importantly you will get highly paid for your work.
 C++ is the most widely used programming languages in application and system
programming. So you can choose your area of interest of software development.
 C++ really teaches you the difference between compiler, linker and loader, different data
types, storage classes, variable types their scopes etc.
 There are 1000s of good reasons to learn C++ Programming. But one thing for sure, to
learn any programming language, not only C++, you just need to code, and code and finally
code until you become expert.
Applications of C++ Programming
C++ is one of the most widely used programming languages. It has it's presence in almost
every area of software development. I'm going to list few of them here:
 Application Software Development
 C++ programming has been used in developing almost all the major Operating
Systems like Windows, Mac OSX and Linux. Apart from the operating systems,
the core part of many browsers like Mozilla Firefox and Chrome have been written
using C++. C++ also has been used in developing the most popular database
system called MySQL.
 Programming Languages Development
 C++ has been used extensively in developing new programming languages like
C#, Java, JavaScript, Perl, UNIX’s C Shell, PHP and Python, and Verilog etc.
 Computation Programming
 C++ is the best friends of scientists because of fast speed and computational
efficiencies.
 Games Development
 C++ is extremely fast which allows programmers to do procedural programming
for CPU intensive functions and provides greater control over hardware, because
of which it has been widely used in development of gaming engines.
 Embedded System
 C++ is being heavily used in developing Medical and Engineering Applications
like softwares for MRI machines, high-end CAD/CAM systems etc.

Time to set up!

1. To downloads neatbeans go to this link:


https://en.softonic.com/download/code-blocks/windows/post-download
2. Select and Click (Download)

3. Go to Downloads Folder and click the file.

4. Click Next
5. Click I Agree

6. Click Next

7. Click Install
8. Wait for the Codeblocks to Install

9. Do you want to Run the Codeblocks now? Click Yes.

Testing the Code blocks:

1. Click the File then Select New, Empty File


2. Write the Program
3. Then save it as File name.cpp.

For more understanding of the history of c++ visit this video on youtube:
https://www.youtube.com/watch?v=SQHREey_Yuc
For more understanding of the codeblocks installation process visit this video on youtube:
https://www.youtube.com/watch?v=GWJqsmitR2I
C++ Basic Syntax

C++ is a general-purpose programming language and widely used nowadays for competitive
programming. It has imperative, object-oriented and generic programming features. C++ runs on
lots of platform like Windows, Linux, Unix, Mac, etc. When we consider a C++ program, it can
be defined as a collection of objects that communicate via invoking each other's methods.
 Object − Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behaviors - wagging, barking, eating. An object is an instance of a class.
 Class − A class can be defined as a template/blueprint that describes the behaviors/states
that object of its type support.
 Methods − A method is basically a behavior. A class can contain many methods. It is in
methods where the logics are written, data is manipulated and all the actions are executed.
 Instance Variables − Each object has its unique set of instance variables. An object's state
is created by the values assigned to these instance variables.
C++ Program Structure
Let us look at a simple code that would print the words Hello World.

Let us look at the various parts of the above program −


 The C++ language defines several headers, which contain information that is either
necessary or useful to your program. For this program, the header <iostream> is needed.
 The line using namespace std; tells the compiler to use the std namespace. Namespaces
are a relatively recent addition to C++.
 The next line '// main() is where program execution begins.' is a single-line comment
available in C++. Single-line comments begin with // and stop at the end of the line.
 The line int main() is the main function where program execution begins.
 The next line cout << "Hello World"; causes the message "Hello World" to be displayed
on the screen.
 The next line return 0; terminates main( )function and causes it to return the value 0 to
the calling process.
Compile and Execute C++ Program
Let's look at how to save the file, compile and run the program. Please follow the steps
given below −
 Open a text editor and add the code as above.
 Save the file as: hello.cpp
 Open a command prompt and go to the directory where you saved the file.
 Type 'g++ hello.cpp' and press enter to compile your code. If there are no errors in your
code the command prompt will take you to the next line and would generate a.out
executable file.
 Now, type 'a.out' to run your program.
 You will be able to see ' Hello World ' printed on the window.
$ g++ hello.cpp
$ ./a.out
Hello World
 Make sure that g++ is in your path and that you are running it in the directory containing
file hello.cpp.
Semicolons and Blocks in C++
 In C++, the semicolon is a statement terminator. That is, each individual statement must
be ended with a semicolon. It indicates the end of one logical entity.
 For example, following are three different statements −
x = y;
y = y + 1;
add(x, y);
 A block is a set of logically connected statements that are surrounded by opening and
closing braces. For example −
{
cout << "Hello World"; // prints Hello World
return 0;
}
C++ does not recognize the end of the line as a terminator. For this reason, it does not matter
where you put a statement in a line. For example −
x = y;
y = y + 1;
add(x, y);
is the same as
x = y; y = y + 1; add(x, y);
C++ Identifiers
 A C++ identifier is a name used to identify a variable, function, class, module, or any other
user-defined item. An identifier starts with a letter A to Z or a to z or an underscore (_)
followed by zero or more letters, underscores, and digits (0 to 9).
 C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is
a case-sensitive programming language. Thus, Manpower and manpower are two
different identifiers in C++.
 Here are some examples of acceptable identifiers −
mohd zara abc move_name a_123
myname50 _temp j a23b9 retVal

C++ Keywords
 The following list shows the reserved words in C++. These reserved words may not be
used as constant or variable or any other identifier names.

Trigraphs
o A few characters have an alternative representation, called a trigraph sequence. A
trigraph is a three-character sequence that represents a single character and the
sequence always starts with two question marks.
o Trigraphs are expanded anywhere they appear, including within string literals and
character literals, in comments, and in preprocessor directives.
Following are most frequently used trigraph sequences −

Whitespace in C++
 A line containing only whitespace, possibly with a comment, is known as a blank line, and
C++ compiler totally ignores it.
 Whitespace is the term used in C++ to describe blanks, tabs, newline characters and
comments. Whitespace separates one part of a statement from another and enables the
compiler to identify where one element in a statement, such as int, ends and the next
element begins.
For more understanding of the basic syntax visit this video on youtube:
https://www.youtube.com/watch?v=gscX6RGYd2k

You might also like