GeekInterview.com
  I am new, Sign me up!
 
Home C
 

Assign values during declaration

 
Category: C
Comments (0)


How to assign values during declaration of variables


Declaring variables tells the compiler the data type the variable is assigned and no storage area is allocated during this stage. It is possible to assign values during declaration itself.


For example, consider the following program:


main()
{
int a= 50 , b= 18 % 5 ;
printf( “a=%d b=%d”,a,b);
}


The above program runs perfectly good and will not give error. In this a is assigned the value of 50 during the declaration as integer itself and similarly b is assigned the result of operation 18 % 5 which gives 3 and this assigned to b during the declaration statement itself which is perfectly correct syntax.


So the output of the above program is


a=50 b=3



Read Next: sizeof Operator



 
Related Topics


 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape