APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY Previous Years Question Paper & Answer

Course : B.Tech

Semester : S1 and S2

Year : 2018

Term : MARCH

Branch : BIOTECHNOLOGY

Scheme : 2015 Full Time

Course Code : CS 100

Page:20





PDF Text (Beta):

/* function definition */ void

func( void ) {

i++;

}

When the above code 15 compiled and executed, it produces the following result -

iis 6 and count is 4 iis 7
and count is 3 i is 8 and
count is 2 i is 9 and count
15111510 and count is 0
The extern Storage Class

The extern storage class is used to give a reference of a global variable that is visible to ALL the program
files. When you use ‘extern’, the variable cannot be initialized however, it points the variable name at a
storage location that has been previously defined.

When you have multiple files and you define a global variable or function, which will also be used in other
files, then extern will be used in another file to provide the reference of defined variable or function. Just
for understanding, extern is used to declare a global variable or function in another file.

The extern modifier is most commonly used when there are two or more files sharing the same global
variables or functions as explained below.

First File: main.c

#include int count ;
extern void

write_extern();

main() { count = 5;
write_extern();

}

Second File:

support.c #include

extern int

count; void
write_extern(void) {
printf("count is %d\n", count);
}

Here, extern is being used to declare count in the second file, where as it has its definition in the first file,
main.c. b)

Similar Question Papers