[go: up one dir, main page]

0% found this document useful (0 votes)
27 views5 pages

Q. Explain Scope of Variable With An Example - Local, Global, Instance

Uploaded by

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

Q. Explain Scope of Variable With An Example - Local, Global, Instance

Uploaded by

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

Q.

Explain scope of variable with an example - local, global, instance


• Scope of variable refers to the part of the program, where it is accessible. The scope of the variable is simply
lifetime of a variable. It is block of code under which a variable is applicable or alive.

• Local Variable is defined as a type of variable declared within programming block or subroutines. It can only be
used inside the subroutine or code block in which it is declared. The local variable exists until the block of the
function is under execution. After that, it will be destroyed automatically. Ex: C/C++

• A Global Variable in the program is a variable defined outside the subroutine or function. It has a global scope
means it holds its value throughout the lifetime of the program. Hence, it can be accessed throughout the program
by any function defined within the program, unless it is shadowed. Ex: C/C++

• Instance variables are declared in a class, but outside a method, constructor or any block. Instance variables are
created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.
Ex: Java
Q. l_value and r_value
• L-value: “l-value” refers to memory location which identifies an object. l-value may appear as either left hand or
right hand side of an assignment operator(=). l-value often represents as identifier.
• An lvalue is an expression that yields an object reference, such as a variable name, an array subscript reference, a
dereferenced pointer, or a function call that returns a reference. An lvalue always has a defined region of storage, so
you can take its address.
• R-value: r-value” refers to data value that is stored at some address in memory. A r-value is an expression that can’t
have a value assigned to it which means r-value can appear on right but not on left hand side of an assignment
operator(=).
• An rvalue is an expression that is not an lvalue. Examples of rvalues include literals, the results of most operators, and
function calls that return no references. An rvalue does not necessarily have any storage associated with it.

#define rvalue 42
int lvalue;
lvalue = rvalue;
Q. Routines
• In computer programming, a routine is nothing but a sequence of code, intended for the execution of user
programs and input/output operations. It can range from a subroutine, co-routine to a function.
• It is called repeatedly by other codes, during the execution of a program.
• A routine, also known as a function with a specified programming interface, in higher-level languages, can be used
in a program to perform a particular task many times, obviously with different data values.
• Whenever a program needs to perform a specific task, the main sequence of logic in a program can branch off to a
common routine when necessary.
• As soon as the routine has been executed, the calling program must resume the execution, by taking over the called
routine.
• The called routine is said to return to the calling program, by executing the return instruction.
Q. Aliasing & Overloading
• Aliasing refers to the situation where the same memory location can be accessed using different names.
• https://www.youtube.com/watch?v=n1roHzWKG5Y
Q. Compilation vs Interpretation
• Compiler transforms code written in a high-level programming language into the machine code, at once, before
program runs, whereas an Interpreter converts each high-level program statement, one by one, into the machine
code, during program run.
• Compiled code runs faster while interpreted code runs slower.
• Compiler displays all errors after compilation, on the other hand, the Interpreter displays errors of each line one by
one.
• Compiler is based on translation linking-loading model, whereas Interpreter is based on Interpretation Method.
• Compiler takes an entire program whereas the Interpreter takes a single line of code.

https://www.guru99.com/difference-compiler-vs-interpreter.html

You might also like