Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Are The Names Used To Represent:, ,,, And: Keywords Cannot Be Used For

The document discusses various programming concepts like identifiers, keywords, variables, data types, operators, control flow statements, functions, and function prototypes. Identifiers are used to name variables, functions etc. and have certain naming rules. Keywords are reserved words that cannot be used as identifiers. Variables store and allow changing data during program execution unlike constants. Functions are blocks of code that perform tasks. Function prototypes provide function signatures outside definitions.

Uploaded by

Jawad Sandhu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Are The Names Used To Represent:, ,,, And: Keywords Cannot Be Used For

The document discusses various programming concepts like identifiers, keywords, variables, data types, operators, control flow statements, functions, and function prototypes. Identifiers are used to name variables, functions etc. and have certain naming rules. Keywords are reserved words that cannot be used as identifiers. Variables store and allow changing data during program execution unlike constants. Functions are blocks of code that perform tasks. Function prototypes provide function signatures outside definitions.

Uploaded by

Jawad Sandhu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

are the names used to represent: , , , , and .

 It is an important feature of all computer languages.


 A good identifier name should be descriptive but short.
 Identifier name consist of up to 31 characters.
 The first character must be an alphabet ( a – z ) or underscore ( _ )
 The reserved / keywords cannot be used as identifier name.

1. : A type of identifiers that has special meaning e.g. &


2. : A type of identifier that is defined by the programmer e.g.
&

 They are reserved identifiers which cannot be used as names for the variables, constants,
Functions and labels in a program.
 List of some keywords is given below:

asm else operator template


auto enum private this
break extern protected throw
case float public try
catch for register typedef
char friend return union
class goto short unsigned
const if signed virtual
continue inline sizeof void
default int static volatile
delete long struct while
double new switch -

Keywords cannot be used for: -


 Declaring Variable Name
 Declaring Class Name
 Declaring Function Name
 Declaring Object Name
are the items whose value cannot be changed during the program execution.

“Talk is cheap. Show me the code.” - - - -by Page 1


 A variable is a named memory location or memory cell.
 It is used to store program’s input data.
 Variables are created in RAM.
 The value of variable may changes during the execution of program.
 The name of the variable cannot be changed during the execution of program.
set of values and a set of operation on those values

 %d signed integer.
 %f float signed decimal.
 %c single character.
An operator is a symbol which tells compiler to take an action on operands
and yield a value. The Value on which operator operates is called as operands. C++
supports wide verity of operators. Supported operators are listed below:
Operator Explanation
Arithmetic Operators Used for arithmetic operations
Relational Operators Used for specifying relation between two operands
Logical Operators Used for identifying the truth value of the expression
Bitwise Operators Used for shifting the bits
Assignment Operators Used for assigning the value to the variable

Operator Description Example


+ Adds two operands or variables A + B = 30
- Subtracts second operand from the first A – B = 10
* Multiplies both operands A * B = 200
/ Divides numerator by denominator A/B=2
% After dividing the numerator by denominator remainder will be returned after division A%B=0
++ Increment operator will increases integer value by one A++ = 21

Symbol Meaning Example


> Greater than A > B returns true
< Less than A < B returns false
>= Greater than equal to A >= B returns false
<= Less than equal to A <= B returns false
== Equal to A == B returns false
!= Not equal to A != B returns true

“Talk is cheap. Show me the code.” - - - -by Page 2


Operator Description Example
AND (&&) If both the operands are non-zero then only condition becomes true (A && B) is false.
OR (||) If both the operands are zero then only condition becomes false (A || B) is true.
NOT (!) It will reverses the state of its operand i.e. true will become false (!A) is true.

Operators Meaning of operators


& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise complement
<< Shift left
>> Shift right

Operator Symbol Name of Operator Example Equivalent Construct


+= Addition assignment a+=5 a=a+5
-= Subtraction assignment a-=5 a=a-5
*= Multiplication assignment a*=5 a=a*5
/= Division assignment a/=5 a=a/5
%= Remainder assignment a%=5 a=a%5

 If is a keyword
 If, is decision making statement.
 If is the simplest form of selection construct.
 If is used to execute or skip a statement by checking a condition.
 The condition, written inside if, is true then if block gets executed.

in this statement:
 Both blocks of statement can never be executed.
 Both blocks of statement can never be skipped.
 Executes one block of statement when the condition is true/false.
 When the if condition becomes true then if block gets executed.
 When the if condition becomes false then else block gets executed.

“Talk is cheap. Show me the code.” - - - -by Page 3


C++ provides the multi-way decision statement which helps to decrease the complexity of the program.
 The switch statement is another conditional structure.
 It is a good alternative of nested if-else.
 It is used for one choice execution between many options.
 Switch statement is the best way to deal with the else-if nesting.

“Talk is cheap. Show me the code.” - - - -by Page 4


 The for-loop is also used to execute some statements repetitively for a fixed number of times.
 Syntax of the for loop is as follow –
for ( init; condition; increment )
{
statement(s);
}

 While loop is used for repetitive execution of the statements based on the given conditions.
 If condition fails then control goes outside the while loop.
 If condition becomes true then while loop body will be executed.
 True condition can be any non-zero number and Zero is considered as false condition
 Syntax: WHILE (condition) { Statements}

 does not test the condition before going in the loop.


 statement allow execution of the loop body once and after the execution of loop body
one time.
 condition will be checked before allowing the execution of loop body for second time.
 is exit controlled loop, i.e. condition will be checked after the execution of the body i.e.
at the time of exit.
 is guaranteed to execute at least one time

“Talk is cheap. Show me the code.” - - - -by Page 5


A function can be defined as “The named block of code that performs some action is called function”.

A type of function written by programmer is called user-defined function


It is a collection of already defined functions in programming framework.
A function that called itself is called recursive function.
The function declared with keyword inline is known as inline function

 It is a model of function
 It is also called function prototype.
 It ends with a semi colon.
 It is required when you define a function in one source file and you call that function in another file.
 It is usually placed just before the main( ).
 It is not required if the function definition is written before main( ).
 Return type + function name + ( parameter list ) + Terminator

int max (int num1, int num2);

“Talk is cheap. Show me the code.” - - - -by Page 6


A set of statements that explains what a function does is called function definition.
 It consist of following two parts:
o : The first line of the function is called function header or function declaration.
o : Set of statements, executed inside the function, is known as function body.
 It can be written in the following places:
o After / Before main() function.
o In a separate file.
o Syntax
Header Return Type + Function Name + (Parameter)
Body {
Statement 1;
Statement 2;
.
.
.
Statement n;
}

 The statement that activate a function is known as function call


 Function is called with its name
 Syntax function Name + (Parameter) + Terminator
 table (num) ;

The area in which a function is visible is known as scope of function

The process of declaring multiple functions with the same name but different parameters
is called function overloading

“Talk is cheap. Show me the code.” - - - -by Page 7


 an Array is the collection of the variables of same type
 An array is a group of consecutive memory locations with same name and type.

The memory locations in the array are known as elements of the array.

The total number of elements in the array is called length of the array

Each element of the array has unique number which is called index

 An array can be passed to a function as parameter


 When an array is passed as parameter to a function, only the address of first
element of the array is passed
 Syntax
Return-type + Function-name + (parameter) + Terminator

Void display (int[]) ;

 A pointer is a variable that is used to store a memory address


 Syntax: data-type + dereference operator + variable name + terminator
 Example: int *ptr;

“Talk is cheap. Show me the code.” - - - -by Page 8


In the above example we have printed the elements of the array using the pointer.
Pointer is special type of variable which stores the address of the variable.
The base address of the array is assigned to the pointer using following statement.
ptr = arr;

Expression Result
Address + Number Address
Address – Number Address
Address – Address Number
Address + Address Illegal

“Talk is cheap. Show me the code.” - - - -by Page 9

You might also like