Home / Programs / variable definition and actual initialization using extern variable in c programming language
🚀 Programming Example

variable definition and actual initialization using extern variable in c programming language

👁 1,274 Views
💻 Practical Program
📘 Step Learning
variable definition and actual initialization using extern variable in c programming language

📌 Information & Algorithm

This C program demonstrates the use of external variable declarations and definitions. External variables a, b, c, and f are declared at the beginning of the program using the extern keyword, indicating they are defined elsewhere. In the main function, these variables are then defined and initialized: a and b are assigned values of 10 and 20, respectively, and c is calculated as their sum. The value of c is printed using printf. A floating-point division is performed, and the result is assigned to f, which is then printed. The program outputs the values of c and f before terminating.

💻 Program Code

#include"stdio.h" 
// Variable declaration:
extern int a, b;
extern int c;
extern float f;

int main () {

   /* variable definition: */
   int a, b;
   int c;
   float f;
 
   /* actual initialization */
   a = 10;
   b = 20;
  
   c = a + b;
   printf("value of c : %d \n", c);

   f = 70.0/3.0;
   printf("value of f : %f \n", f);
 
   return 0;
}
                        

🖥 Program Output

value of c : 30
value of f : 23.333334
Press any key to continue . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.