0% found this document useful (0 votes)
5 views53 pages

Computer Programming Basics Explained

The document provides a comprehensive overview of computer programming concepts, including definitions of computer programs, distinctions between syntax and semantics, and classifications of programming languages into low and high levels. It also covers the structure of C programs, the purpose of comments, data types, variable naming rules, and input/output functions. Additionally, it discusses operators and their types in C language, as well as the order of precedence for operations.

Uploaded by

ahmedmuj9990
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)
5 views53 pages

Computer Programming Basics Explained

The document provides a comprehensive overview of computer programming concepts, including definitions of computer programs, distinctions between syntax and semantics, and classifications of programming languages into low and high levels. It also covers the structure of C programs, the purpose of comments, data types, variable naming rules, and input/output functions. Additionally, it discusses operators and their types in C language, as well as the order of precedence for operations.

Uploaded by

ahmedmuj9990
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

8.1.

1 define a computer program;


 Computer program is a set of instructions given to the
hardware to perform a specific task
 Instructions should be written in a sequence order
8.1.2 differentiate between program syntax and program semantic;

Program Symantec
 Actual meaning or function of program statement

Program syntax
 Rules of programming language to write an instruction

syntax Symantec
Syntax refers to the structure of semantics describes the relationship
a program written in a between the sense of the program
programming language. and the comp`utational model.
Syntactic errors are handled at semantic errors are difficult to find
the compile time. and encounters at the runtime.
8.1.3 differentiate among the following levels of programming languages:

a. LOW LEVEL LANGUAGES b. HIGH LEVEL LANGUAGES


i. machine language i. procedural language
ii. assembly language ii. structured language
iii. object oriented language;

There are two categories of programming languages


Low level languages
High level languages
LOW LEVEL LANGUAGES
Languages directly or close to understandable by computer

Characteristics of low level language

 Complex, difficult and more chances of error


 Machine oriented language
 Machine dependent language
 Machine readable code

There are two types of low level languages


• Machine language
• Assembly Language
Machine language
 It consists on 0 and 1 because computer understand only two states
 directly executed by a computer
 It is also known as binary language
 Quite difficult to understand by human
If you want to add two numbers (83 and -2) with the help of computer
instructions given can be
Assembly language
 It consists of SYMBOLS like ADD, SUB ……
 ASSEMBLER is required to change it into machine language.
 It is also known as SYMBOLIC LAGUAGE
 Quite easier to understand as compare to machine language
If you want to add two numbers (83 and -2) with the help of computer
instructions given can be
HIGH LEVEL LANGUAGES

Languages directly or close to understandable by Human

Characteristics of high level language


 simple easier and less error
 Problem oriented language
 Not a machine independent language
 Highly structured language (reuse the codes of set of codes)
 Human readable code

There are Three types of low level languages


i. procedural language and structured language
ii. object oriented language;
Procedural and structured languages

 Set of instructions make procedure

 Every procedure having their own method and result

 There are number of procedures in a language

 Procedure can also be termed as modular

 It is also called a structured programming

 There are three types of a structure

 Sequence (statement executed in a particular sequence close )

 Selection (statement executed on the basis of a specific conditions)

 Repetition
HIGH LEVEL LANGUAGES
C , C ++
 Design by Dennis Ritchie 1970
 System programs operating systems compiler
 Application programs but processes games

C Sharp
 developed in 2000
 Used to to develop web based applications

Visual Basic
 It is a basic language with graphical features
 Management system environment developed in Visual Basic

Java
 Developed by sun Microsystem company
 Features are similar as c and C plus plus
8.1.4 discuss the characteristics of a high level language;

Characteristics of high level language


 simple easier and less error
 Problem oriented language
 Not a machine independent language
 Highly structured language (reuse the codes of set of codes)
 Human readable code
8.1.5 differentiate among assembler, compiler and an interpreter;
8.2.1 define integrated development environment (IDE);
8.2.2 use the following menus in C programming IDE:

Understanding of INTEGRATED DEVELOPMENT ENVIRONMENT


 Environment for programming
 Different options of programming languages integrated in a single
window
 Dev C plus plus download

CREATING AN ENVIRONMENT BEFORE WRITING PROGRAM


Steps to create environment
 Include header files
 Write main function
 Define body of a function
 And getch() function
8.3.2 describe the structure of a C program consisting of:
a. pre-processor directives
i. include
ii. define
b. main ( ) function
c. body of main { }
d. global and local variables;

PREPROCESSOR DIRECTIVES are lines included in a program that begin with


the character #, which make them different from a typical source code text. They
are invoked by the compiler to process some programs before compilation

 Library and header files are the pre-processor directives


 Programmer must include header files with hashtag before writing main
program.
 Compiler include these files before processing the program
main() function in C
 main() function is the entry point of any C program.
 It is the point at which execution of program is started.
When a C program is executed, the execution control
goes directly to the main() function.
 Every C program have a main() function.

Body of main function


It is the path where program is written in C language
Global variables

Global variables are declared outside any function, and they can
be accessed (used) on any function in the program.

Local variables

Local variables are declared inside a function, and can be used


only inside that function.
8.3.3 describe the purpose of comments in a C program;

comments in a C program
 In computer programming, a comment is a programmer-readable explanation or
annotation in the source code of a computer program.
 They are added with the purpose of making the source code easier for humans to
understand, and are generally ignored by compilers and interpreters.
C Keywords – Reserved Words

In C, we have 32 keywords, which have their predefined meaning and cannot be used
as a variable name. These words are also known as “reserved words”. It is good
practice to avoid using these keywords as variable name. These are –
Basics usage of these keywords –
if, else, switch, case, default – Used for decision control programming structure.
break – Used with any loop OR switch case.
int, float, char, double, long – These are the data types and used during variable declaration.
for, while, do – types of loop structures in C.
void – One of the return type.
goto – Used for redirecting the flow of execution.
auto, signed, const, extern, register, unsigned – defines a variable.
return – This keyword is used for returning a value.
continue – It is generally used with for, while and dowhile loops, when compiler encounters
this statement it performs the next iteration of the loop, skipping rest of the statements of
current iteration.
Constant in C language
Constant is a value which cannot be changed during execution of our program
There are two types of constants
 Numeric constant
 character constant
Numeric constant is a constant in which we apply and arithmetical operation
There are two types of numeric constant
 Integer constant (it contains integer values)
 Real constant (it contains real values)
There are two types of character constant
 Single character constant ('A', 'B', '$')
 String character constant ("Hello", "Engro")
Variable
 Variable is a symbolic name that represent some value that can change

during execution of program

 Variable consist on its name and its value

 Variables are of two main types numeric and character

 Numeric variables are those which contains numeric values

 Character variables are those which contains character values


Rules for naming variables in C language

 Variable begins with the letter for underscore all digit

 Underscore is used to improve the readability of the name of variable

 There is no limit for the length of the variable name however first 31

characters of the variables are significant

 Both upper and lower cases are allowed

 Special characters can not be used

 Space is not allowed in the name of variable


Data types in C language
There are three main data types of c language
 Integer (2 bytes)
 Float (4 bytes)
 Character (1 byte)

 Double (8 byte)
 Long (8 byte signed value)

Memory Structure
Integer data type
 Integer variable can be declared as
 int sum;
 Where int is a type specifier and sum is a name of a variable
 All the variable used in C program must be declared
 Multiple variables declaration
 int a,b,sum;
 Declaration of integer variable can begin with a type qualifier like short long,
unsigned or signed some examples are
 Short int num; long int sum, avg;
 Unsigned int count; Short unsigned int count;
 Qualifier refer to the number of whites reserved for storing the integer on a
particular computer you like
Floating point data type
 Floating-point variables are used to storing decimal numbers

 They are stored in memory into different parts mantissa and exponent examples are

 Float base, height;

 Double float a, b, total;

 Long double float size, x, y;

 In C language a floating point number of type float is stored in 4 bytes. Three bites

of the mantissa and one by for the exponent and provide 6 to 7 digits of precision.
Character data type
 Character variables are used to store character constants examples are

 char ch, letter, a;

 It can store only one character

 1 byte is reserved for a character variable.


Type casting
In C language type casting is a technique by which the type of a variable
can be changed into another type as per required.

Answer = 1.00000
OUTPUT FUNCTION
• Output means to display information on screen a print on printer
• The most common function used for this purpose in C language is
printf()
The printf() function
It is used to print text, constants, values of variables and
expression on the screen in a specified format

Syntax:

Printf(control string, list of arguments);


Printf (control string, list of arguments);

control string
• Control is string consists of
• Text " specifies the message that is to be printed"
• Format specifiers " specifies the format according to
which values of variables is to be printed"
• Escape sequences " controls the printing on Alpha
device"
• It must be in double quotation
Printf (control string, list of arguments);

list of arguments
• List of argument consists of a list of variables, constants and
arithmetic expressions separated by commas values are to be
printed
• Arguments are the variables that is to be printed, each variable
relates with format specifier in control string.
example
• int a=5,b=6;
• Printf("\n the value of a is%d and the value of b is%d.", a, b);
• the value of a is 5 and the value of b is 6.
Format specifier

• It specifies the data type coma in the format according to which the

value is going to be printed

• %d decimal integer

• %i integer

• %ld long decimal integer

• %f floating point(decimal notation)

• %e floating point(exponential notation)

• %c single character
Escape sequence

• Special characters used to control printing on output device


• Non printed characters
• It is used with backslash "\" known as control character
• \a producers alert Bell sound
• \b moves cursor backwards by one position
• \n moves cursor to the beginning of the next line
• \r moves cursor to the beginning of the current line
• \t moves cursor to the next tabular position
• \\ Produce a backslash
• \' produce a single quotation
• \“ produce a double quotation
INPUT FUNCTION
• Input means to enter information into program
• The most common function used for this purpose in C language is
scanf()
The scanf() function
It is used to feed the data into the program.

Syntax:

scanf(control string, list of arguments);


scanf(control string, list of arguments);

control string
Control is string consists of
• Format specifiers " specifies the format according to
which values of variables is to be entered"
• It must be in double quotation
scanf(control string, list of arguments);
list of arguments
• List of argument consists of a list of variables are to be entered.
• Arguments are the variables that is to be entered, each variable
relates with format specifier in control string.
• ampersand sign refer to the memory location address where
the variable is going to store.
example
• int a,b;
• Printf(“enter value of a and b:”);
• scanf("%d %d.", &a, &b);
• Printf(“value of a =%d and b=%d”,a,b);
• the value of a= _ and b = _.
In C language there are three types of operators

• Assignment operators

• Relational operators

• Logical operators
Assignment operators
It is used to assign values to a variable

C language provides three Types of assignment operators

• Basic assignment operator

• Compound assignment operator

• Increment decrement operator


Basic assignment operators
Used to assign the value of an expression to a variable

• Sum = a+b

• a=5
Compound assignment operator
Compound assignment operators modify the current value of a variable by

performing an operation on it. They are equivalent to assigning the result of an

operation to the first operand:

Suppose op represent an arithmetic operator then the compound assignment


operator has the following general form of assign value of an expression to the
variable
Sum= sum - n equivalent to sum -= n
Variable OP = expression
Product= product* n equivalent to product *= n
Equivalent to
a= a/b equivalent to a /= n
Variable = variable op expression
a= a%b equivalent to a %= n
Examples are
Sum= sum + n equivalent to sum += n
Relational operators
Are used to compare two values of the same type and return answer
true or false
there are 6 types of relational operators
Logical operators
They are used for building compound conditions. Single condition is
built using a relational operator. If you want to bill to more than one
condition some action, we have to use compound conditions.
Increment and decrement operators
They are used to increase value of an operand
++n first increase in and then assign
n++ first assign the value and then increase

binary and unary and tertiary operator


Unary operators used with single operand
a=-b
Binary operators used with two operand
a=a+b

Tertiary operator decision making operator.


Condition? expression 1: Expression 2
a=(k>15) ? x*y : x+y
Order of precedence of operators
It is the rule that is specify the order in which operations are to be
performed in an expression
Example 7*10-5%3*4+9/3

You might also like