0% found this document useful (0 votes)
2 views

Variables,errors and control structures

The document explains the concept of variables in programming, including their declaration, initialization, and types (global and local). It also outlines different types of errors that can occur in programming, such as syntax, runtime, logic, semantic, and compilation errors. Additionally, it describes control structures in programming, categorized into sequence, selection, and iteration, which dictate the order and conditions for executing instructions.

Uploaded by

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

Variables,errors and control structures

The document explains the concept of variables in programming, including their declaration, initialization, and types (global and local). It also outlines different types of errors that can occur in programming, such as syntax, runtime, logic, semantic, and compilation errors. Additionally, it describes control structures in programming, categorized into sequence, selection, and iteration, which dictate the order and conditions for executing instructions.

Uploaded by

Hadia Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

VARIABLES

Storage location to store data or


values are called variables .Using
variables we can store values in
program and access them
lately .Variables are the building
blocks of program.
● DECLARATION:
Declaration involves specifying type
and name of variable.
● SYNTAX :
int a =10;
● int is the data type
● a is the name of variable
● 10 is the value of a
● INITIALIZATION:
Involves assigning initial value to a
declared variable .
int num=73;
Variables cannot be initialized
automatically.
Example:
int sum;
The value for the sum of variable can
be anything.
● TYPES:
1. Global
2. Local
COMPARISON

● GLOBAL ● LOCAL
VARIABLES VARIABLES
● Accessible from any ● Accessible only within
part of program. the function.
● Declared outside the ● Declared inside a
function. function.
● Have global scope ● Have local scope that
limited to the duration extends throughout
of the function. the program.
TYPES OF ERRORS
Following are the types of errors.
● SYNTAX ERRORS:
These are the errors in the syntax of
programming language.
example:
Missing semicolon , incorrect keyword
usage , mismatched brackets
● RUNTIME ERROR:
Errors occurring during program execution.
Example: Division of zero , null pointer exception
etc.
● LOGIC ERROR:
Errors in program’s logic that produce in correct
result.
Example: Incorrect algorithm , faulty conditional
statements , incorrect loop iterations.
● SEMANTIC ERRORS:
Errors in the meanings of a program.
Example: Using variable before declaration.
● COMPILATION ERRORS:
Errors occurring during the
compilation of a program are known
as compilation errors.
Example:
Syntax errors , missing header files.
CONTROL STRUCTURES
Programming constructs that allows
developers to dictate orders and
conditions in which specific instructions
are executed. These are categorized into
three types.
● SEQUENCE:
Executes instructions in straight line from
top to bottom. This means each instruction
is performed one after another without
looping.
● SELECTION:
Allows program to choose between different
paths based on the conditions. If –else and
switch statements are used to manipulate
different sets of instructions to be executed
based on different conditions.
● ITERATION:
Known as looping, enables to repeat specific
instructions multiple times. Looping control
structures like for, while and do-while are
extensively used to implement this behaviour.

You might also like