CSC201 Lecture 1 Slide1
CSC201 Lecture 1 Slide1
2
Computer Programming I
At the end of this course you should be able to
Demonstrate an understanding of computer programming
language concepts
Define data types and use them in simple data processing
applications
Understand the concept of pointers, declarations, initialization,
operations on pointers, and their usage.
Understand and apply the concept of array, union, and
enumeration user-defined data types
Demonstrate an understanding of threading and concurrency
Demonstrate an understanding of resource management
Develop C++ programs
3
Brief History of C++
6
Structure of a C++ program
7
Structure of a C++ program
// my first program in C++: is a comment line. C++ comments come in two
types:
•Single-line comments are accomplished using a double slash (//) . The
double slash tells the compiler to ignore everything that follows, until the
end of the line.
•Multiline comments are started by using a forward slash followed by an
asterisk (/*).
#include <iostream>: is a header tag. All lines beginning with a hash sign
(#) are directives for the preprocessor. In this case the directive #include
tells the preprocessor to include the iostream standard file.
8
Structure of a C++ program
using namespace std; All the elements of the standard
C++ library are declared within what is called a namespace,
the namespace with the name std. So in order to access its
functionality we declare with this expression that we will be
using these entities. Without this declaration the expression
cout << "Hello World!";
would be written as
std::cout << "Hello, World!\n";
9
Structure of a C++ program
10
Data types (Variable and constants)
11
Data types (Variable and constants)
Void
Structure
Integral type
Boolean
Union
int
Floating Type
Class
Char
Float
Enum
Double
12
Built-in (Primitive)Data types
int a = 123456789;
int b = 123456789;
int c = a + b;
short d = 1234;
short e = 1234;
short f = d + e;
long g = 123456789;
long h = 123456789;
long i = g + h;
13
Built-in (Primitive)Data types
14
Built-in (Primitive)Data types
15
Built-in (Primitive)Data types
Boolean: This is used for storing Boolean or logical values. Any variable with
this data type can store either true or false. Its Keyword is bool.
16
Built-in (Primitive)Data types
17
Built-in (Primitive)Data types
The list of all the built-in data types with each modifier and their range is given
in the following table.
18
Built-in (Primitive)Data types
The list of all the built-in data types with each modifier and their range is given
in the following table.
Integer types (signed) signed int Not smaller than short. At least 16 bits.
signed long long int Not smaller than long. At least 64 bits.
19
Built-in (Primitive)Data types
The list of all the built-in data types with each modifier and their range is given
in the following table.
20
Variable Name (Identifier)
NOTE: The C++ language is a "case sensitive" language. That means that an
identifier written in upper case letters is not equivalent to another one with the
same name but written in lower case letters. For example, a variable CGPA is
not the same as Cgpa or cgpa.
21
Compound Statement (Block)
Blocks begin with a { symbol, end with a } symbol, with the statements to be
executed being placed in between. Example of a compound statement
{
int a=2;
int b=4;
}
22
Scope and Lifetime of a Variable
The global variable is visible anywhere within the program while the local
variable is only visible within the block or function.
23
Scope and Lifetime of a Variable
Let’s consider the following example:
24
Constants
25
Constants
constexpr
This is used primarily to specify constants that are computed by the
compiler at compilation time. The value is stored in a read-only memory.
26
Constants
27
Literals
Literals are used to express particular values within the source code of a
program.
28
Escape Codes
These are special characters that are difficult or impossible to express in the
source code of a program. Given below is a list of some escape codes
Code Function
\n New line
\r Carriage return
\t Tab
\v Vertical table
\b Backspace
\f Form feed (page feed)
\a Alert (beep)
\’ Single quote(‘)
\” Double quote (“)
\? Question mark (?)
29
\\ Backslash (\)