by Dinesh Thakur Category: Type And Variables

A variable is an object whose value may change during execution of a program. It is a memory location used to store a data value. A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program. Variable names are case sensitive. Others are constants whose values cannot be changed during the execution of the program. However, their values have to be declared. In a program a variable may be declared as below.

 
by Dinesh Thakur Category: Type And Variables

Enumeration is a data type, which is coded as enum, may be used to define user's own data type and define values that the variable can take. The enumeration type is an integral data type. This can help in making program more readable. enum definition is similar to that of a structure. Its syntax is as follows:



 
by Dinesh Thakur Category: Type And Variables

A storage class specifies how the variables are used in the program.

 
by Dinesh Thakur Category: Type And Variables

Static variable is a special variable that is stored in the data segment unlike the default automatic variable that is stored in stack. A static variable can be initialized by using keyword static before variable name.

 
by Dinesh Thakur Category: Type And Variables

First, though there can be many declarations (and in many translation units) of a single ``global'' (strictly speaking, ``external'') variable or function, there must be exactly one definition. (The definition is the declaration that actually allocates space, and provides an initialization value, if any.)

 
by Dinesh Thakur Category: Type And Variables

If you might need large values (above 32,767 or below -32,767), use long. Otherwise, if space is very important (i.e. if there are large arrays or many structures), use short. Otherwise, use int. If well-defined overflow characteristics are important and negative values are not, or if you want to steer clear of sign-extension problems when manipulating bits or bytes, use one of the corresponding unsigned types. (Beware when mixing signed and unsigned values in expressions, though.) Although character types (especially unsigned char) can be used as "tiny'' integers, doing so is sometimes more trouble than it's worth, due to unpredictable sign extension and increased code size.

 
by Dinesh Thakur Category: Type And Variables

The scanf standard library function is used to read one or more values from the standard input (keyboard) and assign them to specified variables. A typical call to the scanf function takes the following form:

 
by Dinesh Thakur Category: Type And Variables

Generally in C program the function definition and calling takes the form as given below:

 
by Dinesh Thakur Category: Type And 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. In order to see how this can be done let us see an example.



 
by Dinesh Thakur Category: Type And Variables

when a variable is not initialized in main function it contains garbage value. This can be well seen from the example below

 

Page 2 of 4



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.