0% found this document useful (0 votes)
43 views8 pages

Document 1

Uploaded by

23-st-037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views8 pages

Document 1

Uploaded by

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

PUNJAB TIANJIN UNIVERSITY OF TECHNOLOGY

BS SOFTWARE ENGINEERING TECHNOLOGY

COMPUTER PROGRAMMING

STUDENT NAME:
MUHAMMAD BILAL SALEEM

ROLL NO. : 16
DATA TYPE
Definition :
Data types are a fundamental concept that defines the type of data
that a particular variable can hold or represent. Following are its types:

Types :

 Integer (int):
Used for whole numbers. It can be either signed (positive and negative
values) or unsigned (only positive values). Examples include 1, -5, and 100.
 Floating-Point (float or double):
Used for numbers with a decimal point. These types can represent both
small and large real numbers with decimal precision. Examples include
3.14, -0.005, and 2.0.
 Character (char):
Used to represent a single character, such as a letter, digit, or special
symbol. Examples include 'A', '7', and '!'.
 String:
A sequence of characters. It is not a primitive data type in all languages but
is often treated as one because of its ubiquity. Examples include "Hello,
World!" and "12345".
 Boolean (bool):
Represents true or false values. Used for logical operations and conditional
statements. Examples include true and false.
 Array:
A collection of elements, all of the same data type, stored in contiguous
memory locations. Elements are accessed by their index. For example, an
integer array might store [1, 2, 3, 4, 5].
VARIABLE
Definition :
A variable is a fundamental concept used to store and manipulate
data within a program or computer programs. It is essentially a named
memory location or storage container with a specific data type that
holds a value. Variables are used to represent and work with different types of
information, such as numbers, text, and more complex data structures, during
the execution of a computer program.

Key characteristics of variables in computer science include:

 Name:
Each variable is assigned a unique identifier (its name) that is used to
reference and manipulate the data it holds. Variable names typically follow
naming conventions and rules, which vary depending on the programming
language being used.
 Data Type:
Variables have a specific data type that determines what kind of data they
can store. Common data types include integers, floating-point numbers,
characters, strings, Boolean values, and more complex types like arrays and
objects. The data type determines the size and format of the data stored in
the variable and dictates the operations that can be performed on it.
 Value:
Variables can hold a value of their assigned data type. This value can be
changed or updated during the execution of a program, allowing the
program to work with and manipulate data dynamically.
 Scope:
Variables can have different scopes, depending on where they are
declared. Local variables are limited to a specific block of code or function,
while global variables can be accessed throughout the entire program. The
scope of a variable determines where it can be used and how long it exists
in memory.
OPERATORS
Definition :
Operators are symbols or special keywords used to perform
operations on data or operands. Operators are a fundamental part of
programming languages, and they allow you to manipulate and work with data in
various ways. The types of operators available in programming languages may
vary, but these are some common categories of operators:

 Arithmetic Operators:
These operators are used to perform basic
mathematical operations on numeric values. Common arithmetic
operators include:

o + (Addition): Adds two or more values together.


o - (Subtraction): Subtracts one value from another.
o * (Multiplication): Multiplies two or more values.
o / (Division): Divides one value by another.
o % (Modulus): Returns the remainder of a division operation.
o ** (Exponentiation): Raises a value to a specified power.

 Logical Operators:
These operators are used to perform logical operations
on Boolean values. Common logical operators include:

o AND (Logical AND): Returns True if both operands are True.


o OR (Logical OR): Returns True if at least one operand is True.
o NOT (Logical NOT): Returns the opposite Boolean value of the
operand.

 Relational Operators:
o Equal to (==): Checks if two operands are equal.
o Not equal to (!=): Checks if two operands are not equal.
o Greater than (>): Checks if the left operand is greater than the right
operand.
o Less than (<): Checks if the left operand is less than the right
operand.
o Greater than or equal to (>=): Checks if the left operand is greater
than or equal to the right operand.
o Less than or equal to (<=): Checks if the left operand is less than or
equal to the right operand.

DECISION MAKING STRUCTURES


Definition :
Decision-making structures in C++ allow you to control the flow of
your program based on certain conditions. C++ provides several ways to
implement decision-making structures:

 If Statement:
The if statement is used to execute a block of code only if a
specified condition is true.

 If-else Statement:
The if-else statement is used when you want to execute
one block of code if a condition is true and another block if the condition is false.

 else-if Ladder:
An else-if ladder is used when you have multiple conditions
to check in a sequence.
 switch Statement:
The switch statement is used when you want to select
one block of code to execute from several options based on the value of an
expression.

 Conditional (Ternary) Operator:


The conditional operator (? :) provides a
concise way to make decisions in a single line of code.

LOOPS
Definition :
In C++, loops are used to execute a block of code repeatedly as long
as a certain condition is met or for a specific number of iterations. C++ provides
three primary types of loops: for, while, and do-while. Here's an overview of each
type of loop:

 for Loop: The for loop is used when you know the number of iterations in
advance.

o SYNTAX:
I. initialization: Typically initializes a loop control variable.
II. condition: Specifies the condition for the loop to continue.
III. update: Updates the loop control variable after each iteration.

 while Loop: The while loop is used when you want to repeat a block of
code as long as a specific condition is true.

o SYNTAX:
I. initialization: Typically initializes a loop control variable.
II. condition: Specifies the condition for the loop to continue.
III. update: Updates the loop control variable after each iteration.
 do-while Loop: The do-while loop is similar to the while loop, but it
guarantees that the loop body will execute at least once because the
condition is checked after the loop body.

Here are some additional loop control statement :


o break: Used to exit a loop prematurely.
o continue: Used to skip the rest of the current iteration and move to
the next iteration.
o goto: Allows you to jump to a labeled statement within your code,
but it is generally discouraged because it can make code less
readable and harder to maintain.

You might also like