You are on page 1of 12

Lecture-3

Programming Fundamentals
Covered ?
• Introduction to program, programming, source code, open source ,
languages , translators
• Types of languages
• Types of translators
• Data types
• Memory reservations and ranges
• Constants
• Variables
Constant?
• Fixed value/data
• Can not be changed at run time
• Single value in an identifier a=10;
• No more than once value acceptance
• If int then we can put only integer data= same / homogenous
• Can be declared within the main body or out of main
• Within main called (local) and out of main called global declaration
• The integer is type of data, ‘a’ is identifier and 10 is fixed value/data
• Used as a medium to store the data (work like a container) – whether data is
being stored temporarily or permanent.
Variable ?
• Single value but variable/ changeable, can be changed at run-time during
execution
• Can be global or local
• Local declaration is within the main
• Global declaration is out of main (above or below but not inside any other
function(user defined function).
• This is also a medium to store the data whether permanent or temporary.
• Permanent means in FILE and temporary means data is stored in primary
memory – will be flushed if the computer is turned OFF.
Homogenous: Int a[5] = {20,30,40,50,60};
Constant Variable Array Structure
Single value Single value Multi-values Heterogenous
Homogenous
Temp/perm Temp/perm Temporary/perm Temporary /
permanent
Medium/container Medium/container = =
Fixed Variable/changeabl = =
e
Same data types Same data types = Int, float, char
may be used may be used. Same DTMBU
Local/global Local / global = =
FILES ARE THE
SOLUTION TO THIS
PROBLEM
DECLARATION OF VARIABLE

Int a; A MEMORY LOCATION IS RESERVED UPTO 2 BYTES (2 BYTES RESERVED)

Where from the variable observe / get the data ?

From: user input, another variable, another constant, a manipulation of


two or more variables/constant
float c, a=10, b=20;
c=(a*b)/(a+b)+1;
10*20) / (10+20) +1
Local Declaration of Variable
#include<conio.h>
#include<stdio.h>
void main()
{
int a; within main (means local declaration)
float b; within main (means local variable)
char c; can be used within main only.
}
It is created within main so it can be used only in the main (local)
We can not use it out of main (even in user defined functions or in any other function
which is used out of main.
GLOBAL DECLARATION
• This type of declaration can be out of main() body
• This is globally declared and can be used out of main () body or within
main () body

• This can also be used in any user defined function which is described
out of main() body.

• Example on next slide.


Example
Int a; GLOBAL DECLARATION
Void main()
{
local declaration portion int a;
rest of program statements portion

getch();
}
GLOBAL CAN BE USED
Int a;
void main()
{
program statements
a is used within the main (though it is declared globally but can be used in
main()
}
USER DEFINED FUNCTION
void user_defined()
{
a is again used here because it can be as it is declared globally.
}
BSCS : you can attend only classes of BSCS
BSCS-2021: you can attend only classes of BSCS OF 2021
BUT IF (NOT POSSIBLE BUT) A STUDENT IS ENROLLED FOR GENERAL
PURPOSE THEN HE/SHE CAN ATTEND ALL CLASSES GLOBALLY.
HE CAN GO ANYWEHRE
HE CAN BE EVALUATED IN ANY DEPARTMENT
HE CAN BE USED ANYWHERE

You might also like