What is the difference between declaration and definition of a variable?
belongs to collection: C interview questions, your interviewer might ask
All Answers
total answers (1)
belongs to collection: C interview questions, your interviewer might ask
total answers (1)
Answer:
Declaration of a variable in C
A variable declaration only provides sureness to the compiler at the compile time that variable exists with the given type and name, so that compiler proceeds for further compilation without needing all detail of this variable. In C language, when we declare a variable, then we only give the information to the compiler, but there is no memory reserve for it. It is only a reference, through which we only assure the compiler that this variable may be defined within the function or outside of the function.
Note: We can declare a variable multiple times but defined only once.
eg,
Definition of a variable in c
The definition is action to allocate storage to the variable. In other words, we can say that variable definition is the way to say the compiler where and how much to create the storage for the variable generally definition and declaration occur at the same time but not almost.
eg,
Note: When you define a variable then there is no need to declare it but vice versa is not applicable.
need an explanation for this answer? contact us directly to get an explanation for this answer