how can we Declare a variable in c without defining it.



how can we Declare a variable in c without defining it...

Answer / manoj

By using EXTRN.
Example:
File 1:

int GlobalVariable; // implicit definition
void SomeFunction(); // function prototype
(declaration)

int main() {
GlobalVariable = 1;
SomeFunction();
return 0;
}

File 2:

extern int GlobalVariable; // explicit declaration

void SomeFunction() { // function header (definition)
++GlobalVariable;
}

Is This Answer Correct ?    6 Yes 1 No

Post New Answer

More C Interview Questions

How the processor registers can be used in C ?

7 Answers   HP,


How does free() know explain how much memory to release?

0 Answers  


Write a code to remove duplicates in a string.

0 Answers   Expedia,


How many levels of indirection in pointers can you have in a single declaration?

0 Answers   Agilent, ZS Associates,


what is difference between C and C++

4 Answers  






A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

0 Answers  


Is it valid to address one element beyond the end of an array?

0 Answers  


How to find the usage of memory in a c program

1 Answers   Infosys,


Write a program to accept a character & display its corrosponding ASCII value & vice versa?

9 Answers  


What are the advantages of using new operator as compared to the function malloc ()?

0 Answers   NIIT,


cavium networks written test pattern ..

0 Answers   Cavium Networks,


What do you mean by a local block?

0 Answers   InterGraph,


Categories