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};
    




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.