Home » C programming language

Variable Initialization in C programming language.



First of all we should learn how to declare a variable in c programming language? There are two things which need to be defined while declaring a variable:

  • Data type - which type of value is going to be stored in the variable.
  • Identifier - Valid variable name (name of the allocated memory blocks for the variable).

Variable initialization

In c programming language, variable can be initialized in the declaration statement of any block (either it may main’s block or any other function’s block).

While declaring a variable you can provide a value to the variable with assignment operator.

Here is the syntax of the variable initialization

data_type variable_name=value;

Integer variable initialization

int number=10;

Float variable initialization

float value=23.45f;

Character variable initialization

char gender = 'M';

Character array/ string initialization

char country_name[]= "India";   
OR
char country_name[10]= "India"; 
/*here 10 is maximum number of character*/
    

Integer array initialization

int arr[]={10,20,30,40,50};
OR
int arr[5]={10,20,30,40,50};
    





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.