Lecture 1
Lecture 1
Paradigms in C++
CSCI 3142
By
Priyanka Samanta
Office hours
By appointment (Preferably on Mon,
Tue, Wed)
Room number: 2122b Ingersoll
Through Blackboard
• Books:
• C++ by Bjarne Stroustrup (advanced)
• Starting Out with C++ from Control Structures to Objects 8 Tony Gaddis
Grades
• Question Types:
MCQ, True/False,
Guess the output,
Find the error, coding
Email
samanta@sci.brooklyn.cuny.edu.
Emails to other addresses will not
necessarily be seen or answered
Communication
Email subject header CISC 3142
must have the MW11– your
following: name – topic.
Why C++
"If there was a programmers party in
which all programming languages and
all programmers in the world are invited,
the C++ programmers would have their
own table".
Why C++
▪ Used to write fast code that performs well ->SIMULA+C
▪ General purpose language: Direct control on hardware
➢ Game industry ->Unity, Unreal, Frostbite
➢ Operating system
➢ Browser, compiler
➢ Embedded system/automation/dabase/photoshop
➢ Big data tensorflow library, Google’s MapReduce
Why C++
▪ Competitors: Rust, Go
▪ Code->compiler->Machine code->CPU executes
▪ Platform independent (Windows, MAC, Linux, IOS, Android, XBOX, Play-station)
▪ Available from 80’s, popular
▪ C++ is a native code (generates machine codes for target platform, no translation
required)
▪ Warning:
Cons of C++
• Complex
• Difficult to learn
• Using an object-oriented programming language like C++ comes with several security issues because of
features like pointers, friend functions and global variables.
• The pointers that are used in C++ take up a lot of memory which is not always suitable for some devices,
and using them incorrectly can cause your whole system to crash or behave strangely, which is a major
drawback.
• Bad C++ code is not fast (slower than C#, Java)
Why C++
This course Covers
▪ Basics of C++ (Briefly)
▪ Use of libraries to enhance performance
▪ Memory management and pointers
▪ Smart pointers
▪ Templates and how to use them properly
▪ Macros
▪ OOP in C++ (class, inheritance, polymorphism)
▪ Data structures using STL
How C++ compiler works
• Preprocessor read the source code (.cpp)
• Preprocessor searches for preprocessor derivatives
(line code starting with a # )
• Preprocessor changes your code by adding
libraries/header files (intermediate file)
• Compiler translates intermediate file line by line to
object file (.obj)
• Check for errors
• Linker combines object file with library files, header
files and create executable code (.exe)
• Loader loads the .exe file to RAM, so that CPU can
execute
• CPU provides output
How interpreter works
• Java script is an interpreted language and Chrome works as interpreter Source code
A common problem of "using namespace std" is if you try to create your own
function and give it the same name that is already present in std namespace,
that can lead to name collisions and ambiguity.
O/p: 1
Modifiers
• Code link:
https://replit.com/@SamantaPriyanka/variables1#float_literal.cpp
Character and character
string literal
• A character literal is created by enclosing a single character inside single
quotation marks. For example: 'a', 'm', 'F', '2', '}' etc.
• A string literal is created by enclosing zero or more characters inside double
quotation marks. For example: "", "x“, "good“, "Earth is round\n“ etc.
Auto
• C++11 feature
• When defining a variable, you don’t actually need to state its type explicitly when it can be deduced from
the initialization.
• With ‘auto’ we use = syntax
• We write auto where we are not worried about precision or clear readability
• Use in generic program when it is hard to know exact object type or the name is quite long