answersLogoWhite

0

What is extern C used for?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

extern specifies that the variable is in another file.

say you have a variable(int k = 10) in mycpp1.cpp and you want to use it in mycpp2.cpp use the extern to redeclare the variable and use it.

Example:

Code:

//mycpp1.cpp

int k = 10;

Code:

//mycpp2.cpp

extern int k;

void function(void)

{

cout << k << endl;

}

this will print

10

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is extern C used for?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How java use extern key word which is used in C plus plus?

No extern keyword in Java.


What does extern C stand for?

"extern" is short of "external" which means outside.


What are the storage classes in c?

A storage class defines the visibility and lifetime of variables or/and functions within a C Program. There are following storage classes which can be used in a C Program: auto register static extern


How do you access extern variable in c?

The usual method: with its name: extern int errno; errno= 17;


What is the function of keyword extern?

The extern keyword declares a variable or function and specifies that it has external linkage (its name is visible from files other than the one in which it's defined). When modifying a variable, extern specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends). The variable or function may be defined in another source file, or later in the same file. Declarations of variables and functions at file scope are external by default. In C++, when used with a string, extern specifies that the linkage conventions of another language are being used for the declarator(s). C functions and data can be accessed only if they are previously declared as having C linkage. However, they must be defined in a separately compiled translation unit. Microsoft C++ supports the strings "C" and "C++" in the string-literal field. All of the standard include files use the extern "C" syntax to allow the run-time library functions to be used in C++ programs. If you find this info useful Please vote!!!


How i useStatic extern int a in c?

No such thing, pick one ot the three: static int x; extern int x; int x;


What is storage classes in c plus plus?

AUTO EXTERN STATIC are the storage classes in c++


Is possible define a structure with extern keyword?

extern is used only when there is a variable or a function name. so here's what you can do, typedef struct{ int data; }my_struct; extern my_struct my_new_struct; Compilers takes this as a *type*.


What object is used for calling the win32 api functions in qtp?

Extern


What is different storage class in c?

Different from what? Storage classes are auto, register, static, extern and typedef (formally).


How can you make an header file in c language?

Using a text editor. Example: /* myheader.h */ #ifndef MYHEADER_H #define MYHEADER_H extern int myvariable; extern int myfunction (int x, int y, int z); #endif


What is the difference between extern and global?

Extern and Global are the storage space in C program. Global provides us to access the variables from anywhere inside the program only whereas Extern provides us to access the variables from outside that program, i,e., some other program.