Solved Question Paper 3

Page 7

Solved Question Papers

C.45

Example: int m; main () { Int I; Float balance; }

The variable m which has been declared before the main is called global variable. It can be used in all the functions in the program. It need not be declared in other functions. A global variable is also known as external variable. The variables I and balance are called local variables. They are visible only inside functions in which they are declared. ‘C’ provides a variety of storage class specifiers that can be used to declare explicitly the scope and lifetime of variables. The concept of scope and lifetime are important only in malfunctioning and multiple file programming. Four storage class specifiers are Auto, register, static, and extern. Auto: Local variable known only to the function in which if is declared, default is auto. Declaration: Auto int x; Auto variables have garbage values unless they are initialized explicitly. Static: Local variable which exists and retains its value even after the control is transferred to the calling function. Declaration: Static int x; Static and extern variables are initialized automatically to zero. (b) Write a short note on call by reference? Ans: Functions are of four types 1. with argument with return 2. no argument with return 3. with argument no return 4. no argument no return While using with arguments case, the arguments may be passed as direct values. Sometimes they are passed with their address. This type of passing address of variable is called call by reference. Using the pointers in function, we can pass the address of variables in the functions. Example: Main() { Int x,y; X=100;


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.