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

Lect 1 Week 3

The document provides an overview of C++ programming fundamentals, focusing on identifiers, keywords, constants, and escape sequences. It explains the rules for creating valid identifiers, lists reserved keywords, and details various escape sequences used to display special characters. Additionally, it includes examples of local and global variables within C++ code.

Uploaded by

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

Lect 1 Week 3

The document provides an overview of C++ programming fundamentals, focusing on identifiers, keywords, constants, and escape sequences. It explains the rules for creating valid identifiers, lists reserved keywords, and details various escape sequences used to display special characters. Additionally, it includes examples of local and global variables within C++ code.

Uploaded by

Umer Blouxh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

PROGRAMMING

FUNDAMENTALS
LAB
Umer Ahmad
Lecture 1
Week 3
IDENTIFIERS , KEYWORDS,
CONSTANT
• 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++ Identifiers • 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++.
Acceptable Identifiers

move_na
mohd Zara abc
me

myname5
a_123 _temp j
0

a23b9 retVal
Invalid Identifiers
• Int

• Pow

• $sum

• Num^3

• Num 1
• 5abc
C++ Keyword
• Thefollowing list shows the reserved words in C++. These
reserved words may not be used as constant or variable or any
other identifier names.
keywords can not be used:

01 02 03 04
Declaring Declaring Declaring Declaring
variable function class objects
name. name. name. name,
CONSTANT
It is an identifier whose value can not be
changed at the execution time of program.
Known as Literals
ESCAPE SEQUENCE
IN C++
Escape Sequences in C++ are used to display special characters in
a string.
• These characters are not displayed in the output.
• Escape Sequences in C++ are used to modify the string.
The list of certain special characters / escape sequence in C++ is as
follow:
ESCAPE SEQUENCES DESCRIPTION

\’ This escape sequence in C++ is used


for Single Quote.

\” This escape sequence in C++ is used


for Double Quotes.

\? This escape sequence in C++ is used


for Question Mark.

\n This escape sequence in C++ is used


for New Line.

\t This escape sequence in C++ is used


for Horizontal Tab.

\v This escape sequence in C++ is used


for Vertical Tab.

\a This escape sequence in C++ is used


for Alarm Beep.

\b This escape sequence in C++ is used


for Backspace.

\f This escape sequence in C++ is used


for New Page.

\r This escape sequence in C++ is used


for Carriage Return.
Program 2
• Write the program with following
output?
•1 47
• 258
• 369

• Only one cout statement


• Use \n and \t
Program 3
Write a program to display
*
* *
* *
* *
*

\n
\t
Variables that are declared
inside a function or block are
local variables.

Local They can be used only by


statements that are inside
Variables: that function or block of code.

Local variables are not known


to functions outside their own.
#include <iostream>
using namespace std;
int main () {
// Local variable declaration:
int a, b;
int c;
// actual initialization
Example 1 a = 10;
b = 20;
c = a + b;
cout << c;
return 0;
}
#include <iostream>

using namespace std;

// Global variable declaration:

int g;

int main () {

// Local variable declaration:

int a, b;

Example 2 // actual initialization

a = 10;

b = 20;

g = a + b;

cout << g;

return 0;

You might also like