Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Declarations

Node:Declarations, Next:, Previous:Integer variables, Up:Variables and declarations



Declarations

To declare a variable, write the type followed by a list of variables of that type:

type_name variable_name_1, ..., variable_name_n;

For example:

int last_year, cur_year;
long double earth_mass, mars_mass, venus_mass;
unsigned int num_pets;

long city_pop, state_pop;
state_pop = city_pop = 5000000;

short moon_landing = 1969;

float temp1, temp2, temp3;
temp1 = 98.6;
temp2 = 98.7;
temp3 = 98.5;

double bignum, smallnum;
bignum = 2.36e208;
smallnum = 3.2e-300;

Always declare your variables. A compiler will catch a missing declaration every time and terminate compilation, complaining bitterly. (You will often see a host of error messages, one for each use of the undeclared variable. See Debugging.)

 
 
  Published under free license. Design by Interspire