0% found this document useful (0 votes)
35 views45 pages

Name..Haris Malik

The document contains information about Haris Malik, including his name, roll number, address, and mobile number. It then provides an introduction to C/C++ programming, covering basic concepts like character sets, reserved words, user-defined words, variables, constants, and variable types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views45 pages

Name..Haris Malik

The document contains information about Haris Malik, including his name, roll number, address, and mobile number. It then provides an introduction to C/C++ programming, covering basic concepts like character sets, reserved words, user-defined words, variables, constants, and variable types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 45

NAME..

HARIS MALIK
ROLL.NO..122
FIST SAMISTER

ADDRES.CHATO CHOK
MARDAN
MOBILE NO 03070991997
C/C/++
Introduction
 Writing a computer program is like building a house.
 To do a good job, certain fundamental construction
materials are required and one must know how to use
these materials.
 In the same way, C program is constructed from C
statements or instructions.
 C statements can be constructed from numbers,
expressions, reserved words, and user-defined words.
C/C++ Character Set
 C character set consists of Numeric characters,
Alphabetic characters, Special characters, and white
space characters.
 Numeric Character Set: Numeric characters are
0,1,2,3,4,5,6,7,8 and 9.
 Alphabetic Character Set: Alphabetic characters are
upper and lower-case letter of the English language
(A,B,C,…..Z, a,b,c,….z)
Special Characters Set
 The special character are period (.), Comma(,),
Semicolon (;), Colon(:), Single and Double quotes (‘
& “), plus and minus sign (+ -), Asterisk (*), Slash
(/), Back slash(\), Equal sign (=), Parenthesis ( ),
Percent sign (%), less and greater signs (< >), Hash
or number sign (#), Ampersand (&), Question Mark
(?), opening and closing braces ({}) and a blank
character which is equivalent to a space on keyboard.
White Space Characters
 Any character that produces blank space when
printed is called a white space character.
 The white space characters are spces, tabs, new lines
and comments.
 These are used to make your programs more readable
and easier to maintain.
 For example, the statement z=x+y can be written as:
 z=x+y
C/C++ Reserved Words
 Reserved words or keywords are those words that are
reserved for specific purpose and cannot be used for
other purposes.
 They have special meanings and compiler knows
their meanings.
 In C/C++ all keywords are in lower-case.
 Since upper case and lower-case characters are not
equivalent in C/C++, therefore the keywords must be
entered in lower-case and must be spelled correctly.
Contd…
 Reserved words cannot be used as user-defined
names.
 Some of the most frequently used C reserved words
are given below:
 Break default for regular while
 Case do goto return struct
 Char double if short switch
 Else int singed float
User-Defined Words
 Words that are not reserved are called User-defined
words or programmer-supplied names, because the
programmer makes them.
 Such words are also known as data names or
identifiers.
 Data names are most common type of user-defined
words.
 Data is stored in such positions that it can be referred
to by name.
Contd…
 The word identifier is used as a general terminology
for names given to variables, constants, arrays,
functions, file-names etc.
 Thus data-names are only one from of identifiers.
Rules for Identifiers
1. Legal characters of user-defined names include
letters (A to Z or a to z), digits (0 to 9) and only
special character underscore ( _ ).
2. Identifiers must be unique in a program, just as the
Roll-numbers of the students are in a class are
unique.
3. Both upper and lower-case letters are allowed in a
C/C++ program. But since C/C++ is a case-sensitive
language, therefore it distinguishes between
uppercase and lowercase letters.
Contd…
 For example TAX, Tax, TaX or tax are four different
identifiers.
 Similarly, RNO is different from Rno which is

different from rno.


4. The identifiers must start with a letter or an
underscore. After the first letter or underscore, you
can use letters, numbers.
5. The only character must be alphabet.
Contd…
6. Identifiers names may be of any length. However,
not all characters in an identifier name will
necessarily be significant. In C, at least the first 31
characters will be significant, whereas, in C++ there
is no limit to the length of an identifier; however, at
least the first 1024 characters are significant.
7. No space is allowed in an identifier.
8. Reserved words cannot be used as an identifier.
Contd…
9. It is always a good programming practice to choose
names that have some meaning. For example, the
identifier RADIUS is more meaningful than the
identifier r.
Examples of Valid Identifiers
 RNO R_NO ACC_NO
 Z ID_CARD_NO A1234_56
 Sumoftotal Sub_of_total Sum
Some Examples of Invalid Identifiers
 3M The first character must be letter or underscore.
 What? Illegal character (?)
 ‘X’ Illegal character (‘)
 Net-Pay Illegal character ( - )
 Item Name Illegal character (space)
 If C/C++ keyword.
 _ Underscore alone.
Variables
 A value which may change during program execution
is called a variable.
 Each variable has a specific storage location in
memory where its value is stored.
 We may think of a variable as a name of a box in
memory.
 The box can hold any value that can fit in the
variable.
Contd…
 For example:
A
 A=5
 5

 In the above example, a is a variable, which holds a


value 5.
 It is important to know that the value of a variable
may change from time to time during the execution of
a program, but the name remains same.
Contd…
 A variable in a program can hold numeric data as well
as non-numeric data.
 A=5
 B = 3.14159
 C = ‘*’
Naming Variables
 Each variable has a name, a type and a value that you
assign to it.
 A variable name must be unique in a program.
 All identifiers rules must be observed in naming
variables.
Variable Types
 Variables can hold different types of data.
 In C/C++ data may be divided into integer, floating
point and character data.
 Variables that hold the integer data, is known as
integer variable.
 Integer type can further be divided into two verities;
signed and unsigned.
Contd…
 Signed integers are either negative or positive.
 Unsigned integers are always positive.
 Sometimes we deal with very large number or very
small number, therefore, an integer may either be
short or long.
 A short integer is two bytes, whereas a long integer is
four bytes long.
Contd…
 Like integer, floating-point variables hold real
numbers and character variables hold a single
character.
 The table on next slide shows a list of variable types
and ranges that each variable might hold.
Contd…
Declaration Name Type Size Range

Short Int Short Integer 2 bytes -32768 to 32767

Signed Short int Signed short integer 2 bytes -32768 to 32767

Unsigned Short int Unsigned Short Integer 2 bytes 0 to 65535

Long int Long Integer 4 bytes -2,147,483,648 to


2,147,483,648

Signed Long Int Signed Long Integer 4 bytes -2,147,483,648 to


2,147,483,648
Unsigned Long Int Unsigned Long Integer 4 bytes 0 to 4294967295
Contd…
Declaration Name Type Size Range

Float Floating point 4 bytes -3.4E+38 to 3.4E+38


Contd…
 It is worth mentioning here that different computers
and compilers may allow for different ranges.
Constants
 Unlike variables, a constant is a fixed value that does
not change during the execution of a program.
 In simple words, we can say that constants are values
while variables are holders of these values.
 In C/C++ constants are of two types.
 Numeric Constants
 Non-numeric Constants
Numeric Constants
 Numbers are referred to as numeric constants. It can
contain:
 1. Numeric digits 0 to 9
 2. Plus (+) or (-) sign
 3. Decimal point
 No commas or blanks are allowed in numeric
constants.
 A few examples of numeric constants are 25, 0.0,
+100, -300, 3.14159 etc.
Non-Numeric Constant
 Non-numeric constants are used for non-numeric
purposes.
 Such as to produce output reports, heading or printing
messages etc.
 Non-numeric constants are divided into two types;
character constant and string constant.
Character Constant
 In C/C++, character constants are enclosed in single
quotes.
 It is important to note that the single quotes are not part
of the character constant, but they serve to delimit it.
 Some examples of the character constants are:
 ‘Z’ ‘3’ ‘*’ ‘=‘ ‘.’.
 All the alphabetic, numeric and special characters on
keyboard can be character constants.
String Constant
 Any character or sequence of characters between
double quotes is known as a string constant or simply
a string.
 Character within double quotes may be digits,
alphabets or special characters as well as blank space
and reserved words may also be used in double
quotation marks.
 Double quotation marks are not part of the string
constant.
Contd…
 They are only used to delimit the string.
 If either the beginning or the ending double quote is
missing, an error will result.
 A few examples of string constants are:
 “HELLO!” “123.45” “ “ “Tufail”
 “Government College of Management Science,
Swabi”
 “-----------------------------------------------------------”
Contd…
 All the alphabetic, numeric, and special characters on
our keyboard can be a string constant.
Operators
 An operator is a symbol that causes the compilers to
take an action.
 An operator works on data. It is used to perform
arithmetic calculations.
 C/C++ is a language that comes with a rich and
powerful set of operators.
 More than 45 operators are available in C/C++.
 Operators, along with their brief description, are on
the next slide.
Contd…
Operator Description

1. Assignment operator Equal sign (=) is the assignment


operator

2. Arithmetic operator +, -, *, / and % are arithmetic operators.

3. Increment & Decrement operators ++ and - - are increment & decrement optrs.

4. Relational Operators = = , <, >, <=, >= and !=

5. Compound Operators We can combine the arithmetic operators


with the equal sign to form compound
assignment operators. These are +=, -=,
*=, /= etc.

6. Conditional operator ?: is the conditional operator.


Expressions
 An expression in C/C++ is any valid combination of
operators, constants and variables.
 All expressions are statements.
 An expression is used to perform arithmetic
operations to return a value.
 Thus, the expression 2+3; returns the value 5.
 An expression may be defined in many different
ways.
Contd…
 1. The expression may consist of a single entity; such
as a constant, variable etc. For example:
 7 (integer constant) 3.2 (float constant)
 Z (a variable) PI (float constant)
 2. An expression may be a combination of variable
and/or constant linked with the arithmetic operator(s).
 For example:
 X= 5 + 6 X= A + B X=Y
 Z=(X + B*B – 4 * A *C)
Contd…
 3. An expression can also represent logical conditions
that are either true or false.
 For example:
 X==Y X <= Y
C/C++ Statements
 A statement is an instruction or a group of
instructions that carry out certain action.
 C/C++ statements are free format: they may appear
anywhere on a line.
 All C/C++ statements end with a semicolon.
 C/C++ statements can be divided into two types,
these are:
 1. Simple Statement
 2. Structure Statement
Simple Statement
 A simple statement consists of an expression to be
evaluated, followed by a semi colon.
 Assignment statement and input/output statements are
examples of simple statement.
 For example:
 X = 5;
 Z = X + Y;
 cout<<“Hello World”;
Structure Statement
 Structure statement can further be divided into three
types. These are:
 1. Compound Statement: The statements written in
a pair of braces are considered to one compound
statement.
 A compound statement consists of several individual
statements enclosed within a pair of braces.
 For example:
Contd…
 {
 Pi = 3.14159;
 Circumference = 2.0 * Pi * radius;
 Area = Pi * radius * radius;
 }
Selection Statement
 Selection statement is used to choose among
alternative courses of action.
 if (Marks > 33)
 cout<<“Pass”;
 else
 cout<<“Fail”;
 C/C++ supports two types of selection statements; if-
else and switch.
Iteration Statement
 Iteration statements or looping statements are used to
perform an action repeatedly while some condition
remains true.
 For example:
 count = 1;
 while (count <=5)
 cout<<“Pakistan”;
 count++;
 }
Contd…
 In C/C++, the looping statements are for, while and
do-while.

You might also like