in Unknown Category
394 views
1 vote
1 vote
Whenever we declare a variable then compiler will not look for other details such as definition of the variable. why is this statement true ?
in Unknown Category
by
394 views

2 Answers

2 votes
2 votes
Best answer

Explanation :  The compiler only needs to have a declaration for something in order to compile a file into an object file, expecting that the linker (you might have heard these terms as Linker and Loader) can find the definition from another file. If no source file ever defines a symbol, but it is declared, you will get errors at link time complaining about undefined symbols.

selected by
0 votes
0 votes
variable in simple terms is a storage place which has some memory allocated to it
when we declare a variable memory is not allocated for that that's why we can declare variable more than one time but it should be defined only once. At the time of definition, memory is allocated for it


// This is only declaration. y is not allocated memory by this statement 
  extern int y; 

  // This is both declaration and definition, memory to x is allocated by this statement.
  int x;

we can do both declare and define at same time

we need seperate declaration and definition in case of extern and functions.

u can refer: http://quiz.geeksforgeeks.org/commonly-asked-c-programming-interview-questions-set-1/

by

1 comment

@cse23 can we declare a variable in the same scope more then once ?
0
0

Related questions