Computer Science, asked by harshitgoyal580, 5 months ago

What is storage class for variable num in the below code?

int main()

{

int num;

num = 10;

printf("%d", num);

return 0;

}


Select one:
a.
extern

b.
auto

c. register
d. static

Answers

Answered by gandhikeshav862
2

Answer:

Explanation:

Storage Classes in C: auto, extern, static, register with Example

What is a Storage Class?

A storage class represents the visibility and a location of a variable. It tells from what part of code we can access a variable. A storage class is used to describe the following things:

The variable scope.

The location where the variable will be stored.

The initialized value of a variable.

A lifetime of a variable.

Who can access a variable?

Thus a storage class is used to represent the information about a variable.

NOTE: A variable is not only associated with a data type, its value but also a storage class.

There are total four types of standard storage classes. The table below represents the storage classes in 'C'.

Storage class Purpose

auto It is a default storage class.

extern It is a global variable.

static It is a local variable which is capable of returning a value even when control is transferred to the function call.

register It is a variable which is stored inside a Register.

Answered by qwvilla
0

Option b.auto is the correct answer.

Storage class for variable 'num' in the given code is automatic storage class.

  • A storage class defines the scope (visibility) and life-time of a variable , function or method within a C Program.

  • The four types of storage class are : Extern storage class, automatic storage class, register storage class and static storage class.

  • The default storage class for all local variables is the auto storage class.

  • To give a reference of a global variable that is visible to ALL the program files, extern storage class is used.

  • The register storage class is used to indicate the compiler that the object should be stored in a machine register.

  • In order to instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope, static storage class is used.

#SPJ3

Similar questions