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";   
char country_name[10]= "India"; 
/*here 10 is maximum number of character*/

Integer array initialization

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

C Language Tutorial »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.