How is an external variable defined? How is it initialised? What happens when an external variable definition does not include the assignment of an initial value?
An external variable is a variable that is declared outside of any function and can be accessed by multiple source files within a program. It is declared with the `extern` keyword in the files where it is used, and its definition (memory allocation) typically resides in one of the source files.
1. **Definition of an External Variable**:
An external variable is defined in one source file without using the `extern` keyword. This definition reserves memory for the variable. For example:
// File: file1.c
________ ________ ________ _________ ______ ____ __________ ___.
____ __________ _________ ________ ___ _______.
______ _____ __________ ____ _________ ______ ________ ______ ____ __________ ____.
_________ ______ _____ ___ _________ ________ __________ ________ _____.
__________ _____ ______ ________ ________ __________.
___ ________ ________ _______ __________ ____ _____ ________ _______ ___ ____.
___ ______ ______ ________ _____.
_____ __________ ___ ___ _______ _________ _______ __________ ___ _________ _________ ______.
__________ ___ _____ _____ ________ __________ ______.
__________ _____ ______ ______ __________ _______ _____ ___ ________ _______ ________ _______.
______ ___ _____ _____ __________.
____ ________ ________ _________ __________.
__________ _______ __________ ___ __________ ______ ____ ___ ____.
_________ _____ ___ _________ ____ _________ _______ _____ _______ ______.
___ _______ ________ ________ _____ ______ _______ _____ ________ _________ _______.
_________ _____ ______ ___ ______ ________ ___ ___.
_________ _______ ________ _______ _________ _______ _______ ______ _________ ______ _______ ________.
__________ ____ ___ ____ __________ ________ ____ __________ ____ _____ __________.
___ __________ ____ ________ _______ _______ ______ _______ __________ ________ ___ _______.
_____ __________ ___ ____ _____ ________ _____.
_______ ______ _________ ________ __________ _____ ___ _____ _____ __________.
____ _______ _____ _________ ___ _________ _______ ____ ____ ____ _________.
_______ ____ _________ ___ ______ __________ ________.
_________ ______ _____ _________ ___ __________ ________ _________ ______ ______ ____ ________.
__________ ____ ________ ________ ______ _____ ________.
________ ___ ___ _________ ____.
______ _________ ___ __________ ________ ___ _____ ______ _________ ____ ___.
_________ _________ _____ ___ __________ _________ ___ _________ ________ __________ _____.
_________ _______ _______ ____ ________ _______ ______ __________ ________ _______.
______ ____ _________ __________ _________ _______ __________.
___ _______ ________ _____ _________.
Get Full Answer on WhatsApp