Home / Programs / Variable definition and actual initialization, return type int
Programming Example

Variable definition and actual initialization, return type int

👁 3,807 Views
💻 Practical Program
📘 Step by Step Learning
Study this program carefully to understand the logic, output, and explanation in a structured way.

Program Code

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

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

Output

value of a : 15
value of b : 26
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 */

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.