0% found this document useful (0 votes)
13 views16 pages

1 Chapter-1-The-Basic

Uploaded by

hachikomax27
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)
13 views16 pages

1 Chapter-1-The-Basic

Uploaded by

hachikomax27
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
You are on page 1/ 16

Chapter 1 :

Introduction to C++
CMPE 20012 Computer Fundamentals & Programming

Asst. Professor JOHN MICHAEL LEGASPI


Faculty | Institute of Technology
What is C++
• C++ is a cross-platform language that can be used to create
high-performance applications.
• C++ is a powerful general-purpose programming language.
• C++ was developed by Bjarne Stroustrup, as an extension to
the C language.
• C++ gives programmers a high level of control over system
resources and memory.
• The language was updated 3 major times in 2011, 2014, and
2017 to C++11, C++14, and C++17.
Why C++ ?
• C++ is one of the world's most popular programming
languages.
• C++ can be found in today's operating systems, Graphical User
Interfaces, and embedded systems.
• C++ is an object-oriented programming language which gives a
clear structure to programs and allows code to be reused,
lowering development costs.
• C++ is portable and can be used to develop applications that
can be adapted to multiple platforms.
• As C++ is close to C# and Java, it makes it easy for
programmers to switch to C++ or vice versa
The BASIC’s
C++ Variables
• A variable is a name which is associated with a value
that can be changed.
• In programming, a variable is a container (storage area)
to hold data.
Rules for naming variables
• A variable name can only have alphabets, numbers, and the
underscore _. ( A-Z ) , 1-0 / c_name – c name
• A variable name cannot begin with a number. 1add, add, 1no
no1
• Variable names should not begin with an uppercase character.
Char NAME , - char name;
• A variable name cannot be a keyword. For example, int is a
keyword that is used to denote integers. char chars
• A variable name can start with an underscore. However, it's not
considered a good practice. Char _name ; int no1;
Types of Variable
• Global Variable
A variable declared outside of any function (including
main as well) is called global variable. Global variables
have their scope throughout the program, they can be
accessed anywhere in the program, in the main, in the user
defined function, anywhere.
• Local variable
Local variables are declared inside the braces of any
user defined function, main function, loops or any control
statements(if, if-else etc) and have their scope limited
inside those braces.
C++ Data types
Data types define the type of data a variable can hold, for example an integer
variable can hold integer data, a character type variable can hold character
data etc.
Data types in C++ are categorized in three groups: Built-in, user-
defined and Derived.

Derived types in C++


C++ Data types
C++ Operators
1) Basic Arithmetic Operators – ( + , - , * , / , %)
2) Assignment Operators – (=, +=, -=, *=, /=, %= )
3) Auto-increment and Auto-decrement Operators ( ++, -- )
4) Logical Operators - (&&, ||, ! )
5) Comparison (relational) operators – (==, !=, >, <, >=, <= )
6) Bitwise Operators – (&, |, ^, ~, <<, >> )
7) Ternary Operator
Example : Arithmetic Operators
#include <iostream>
using namespace std;
int main(){
int num1 = 240; int no2; float pie = 3.14;
int num2 = 40;
cout<<"num1 + num2: "<<(num1 + num2)<<endl;
cout<<"num1 - num2: "<<(num1 - num2)<<endl;
cout<<"num1 * num2: "<<(num1 * num2)<<endl;
cout<<"num1 / num2: "<<(num1 / num2)<<endl;
cout<<"num1 % num2: "<<(num1 % num2)<<endl;
return 0; }
Example : Assignment Operators
#include <iostream>
using namespace std;
int main(){
int num1 = 240;
int num2 = 40;

num2 = num1;
cout<<"= Output: "<<num2<<endl;
num2 += num1;
cout<<"+= Output: "<<num2<<endl;
cout<<"-= Output: "<<num2<<endl;
num2 -= num1;
return 0; }
Example : Logical Operators
#include <iostream>
using namespace std;
int main(){
int num1 = 240;
int num2 = 40;

num2 = num1;
cout<<"= Output: "<<num2<<endl;
num2 += num1;
cout<<"+= Output: "<<num2<<endl;
cout<<"-= Output: "<<num2<<endl;
num2 -= num1;
return 0; }
C++ Basic I/O
#include <iostream>
using namespace std;

int main() {
cout << ” C++ Programming !!! ";
return 0;
}

You might also like