Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

C extern

Dark Dugong answered on April 13, 2022 Popularity 10/10 Helpfulness 2/10

Contents


More Related Answers

  • add c program
  • what is the usage of extern in c
  • exec c
  • what to include in basic C
  • increment c
  • what is executable file in c
  • sample usage of the extern keyword in c

  • C extern

    2
    Popularity 10/10 Helpfulness 2/10 Language c
    Tags: c extern
    Link to this answer
    Share Copy Link
    Contributed on Apr 13 2022
    Dark Dugong
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0

    ############## External File to Import with Original Variable (var) Definition #########

    filename: my_variable.c

    int var = 22;

    ################ Calling Main Function ####################3

    filename: main.c

    #include

    /* After importing the external variables file Compilation will work*/

    #include "my_variable.c"

    /**

    * Extern keyword means that

    * during linking the compiler will scan through

    * all other c-file and locate a defined variable

    * "int var = "

    * and incorporated to this main function

    */

    extern int var;

    int main(int argc, char **argv, char **envp)

    {

    printf("Original value is %d\n",var);

    var = 10;

    printf("Updated value is %d\n",var);

    return (0);

    }

    /* Compiling this program will fail because the var variable is not defined

    * anywhere in the program*/

    /**


    ######## Compiling the Program #############333

    $ gcc main.c -o a.out

    $ ./a.out

    # program Output #

    Original value is 22

    Updated value is 10


    Popularity 10/10 Helpfulness 1/10 Language javascript
    Tags: c
    Link to this answer
    Share Copy Link
    Contributed on Mar 06 2023
    Nice Narwhal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.