Computer Science, asked by fardeen71, 1 year ago

program uses a function named convert() in addition to its main function. The

function main() declares the variable x within its body and the function convert

declares two variables y and z within its body, z is made static. A fourth variable m is

declared ahead(ie at top) of both the functions. State the visibility and lifetime of

each of these variables.


kishorcash2011: Tell answer plz

Answers

Answered by jgpilapil
10

Based on the information of the program structure you gave, the declaration of variables would look like this:


//-- start of program --//


var m;


function main() {

    var x;

    ...

}


function convert() {

    var y;

    static var z;

    ....

}


//-- end of program  --//


Here, the variable "m" is accessible throughout the entire program (that is, outside and inside of any of the functions). This variable is called a global variable. It's created when the program starts and is destroyed when the program ends.


The variable "x" is only accessible inside the main() function. It's created when the program execution enters the main() function and is destroyed when the program execution exits the main() function.


The variable "y", much like "x", is only accessible inside the function it's declared. In this case, inside the convert() function. It's lifetime starts when the program execution enters the convert() function and ends when the program execution exits the convert() function.


The variable "z" is only accessible inside the convert() function as well. However, because it's declared static, it's initialized only ONCE, and that is when the program execution FIRST enters the convert() function and is destroyed ONLY when the program ends.

Answered by mayurkokane004
1

Answer:

A program uses a function named convert() in addition to its main function. The

function main() declares the variable x within its body and the function convert

declares two variables y and z within its body, z is made static. A fourth variable m is

declared ahead(ie at top) of both the functions. State the visibility and lifetime of

each of these variables.

Similar questions