Home / Programs / Variable definition and actual initialization
🚀 Programming Example

Variable definition and actual initialization

👁 5,963 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

#include "stdio.h" 
void main() {

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

🖥 Program Output

value of a : 10
value of b : 20
Press any key to continue . . .
                            

📘 Explanation

Question: What is the difference between declaration and definition of a variable?


Answer: Declaration specifies the properties of a variable. For example:



int x; /* x is an integer */
int roll_no[]; /* roll_no is an array of integers */


Definition declares a variable and causes the storage to be allocated. For example:


int x = 10; /* x is declared as an integer and allocated space and initialized to 10 */
int roll_no[100]; /* roll_no is declared as an array of integers, allocated space for 100 integers */
📚 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.