Docsity

BCSE102L- Structured and object oriented programming 2026, Exams of Javascript programming

Partial preview of the text

Download BCSE102L- Structured and object oriented programming 2026 and more Exams Javascript programming in PDF only on Docsity!

BCSE102L- Structured and object-

oriented programming 2026

Module 2 Dr. P.Keerthika Associate Professor School of Computer Science & Engineering VIT,Vellore.

BCSE102L- Structured and object-oriented programming

BCSE102P- Structured and object-

oriented programming Laboratory

BCSE102L- Structured and Object-

Oriented Programming

⚫ Module-2:ARRAYS AND FUNCTIONS ◦ Arrays – 1D & 2D ◦ Strings and its operations ◦ User defined Functions 🞄 Declaration and Definition 🞄 Call by Value and Call by reference 🞄 Types of Functions- Recursive Functions ◦ Storage Classes 🞄 Scope,Visibility and lifetime of variables

Scope,Visibility & Lifetime

int a; void main() { char b ; { float c; } } Scope of a Visibility of a Lifetime of a Scope of b Visibility of b Lifetime of b Scope of c Visibility of c Lif

Categories of Storage Classes

⚫ Storage class of a variable tells the compiler ◦ Storage area of the variable ◦ Initial value of the variable if not initialized ◦ Scope of the variable ◦ Life of the variable that is how long the variable would be active in the program. ⚫ Four Categories ◦ Automatic Variables ◦ Static Variables ◦ External Variables ◦ Register Variables

External Variables ⚫ Variables that are active throughout the entire program are called as external variables ( global variables). External variables are declared outside the function body. ⚫ Variable retain the value throughout the execution of a program. This storage class can be accessed by any function in same or different program file and change its value. int number; float length=6.2; main() { } function1() { } function2() { }

  • ---- ;
  • ---- ; ;

External Variables int fun1(void); // Other way of declaring nil arguments int fun2(void); int x; /GLOBAL/ main() { x=10; /GLOBAL / printf(“x=%d\n”, x); printf(“x=%d\n”, fun1()); printf(“x=%d\n”, fun2()); } Int fun1(void) { x=x+10; /GLOBAL/ } int fun2(void) { int x ; /LOCAL/ x=1 ; return(x) ; }

Static Variables ⚫ Static variable may be either an internal type or an external type depending on the place of declaration. ⚫ Global and Local variable can be declared static. Static variables are initialized only once when they are compiled in a program. ⚫ Variable can be declared using the keyword static. ⚫ Internal Static Variables - They are local to the block in which declared. It exists until the end of the program. ( Note: Like an auto variables ). When the program is closed the function associated with that program is also excited and whenever it is visited again the same value exists. ⚫ External static variable is declared outside of all functions. It is made available to all functions in a C program.

Static Variables void start(void); void main() { int i; for(i=1;i<3;i++) start(); } void stat(void) { static int x=0; // Initialized once x=x+1; printf(“x=%d\n”,x); } Output??

Register Variables void main() { register int x; for(x=1;x<=10;x++) printf(“%d”,x); printf(“%u”,&x); // Not able to get the address } int main() { int i = 10; register int a = &i; printf("The value of pointer : %d",a); return 0; }