-->
Showing posts with label extern. Show all posts
Showing posts with label extern. Show all posts

Thursday, July 3, 2025

c program to use global variables | extern examples in c | C program to use multiples files using extern

 

global variables in C

 /* program to input a number from a different file using external variable and print that

*/

step1:

in devc++,

->click file menu

->click new

->project


-> click console application
->choose c project

->click ok

step 2


under 'main.c' write the code

#include <stdio.h>
extern int a;
void input();
int main() 
{
input();
printf("a=%d",a);
return 0;
}

-------

step 3

->right click the project folder on left side

->click new file as shown above . You can give a name you like
 Here we have taken as untitled3.c

->write the following code
#include<stdio.h>
int a;
void input()
{
 scanf("%d",&a);
}


->save it

->run the program