C Programming language

C Declaration
Previous Home Next

Declaration of Storage Class

Variables in C have not only the data type but also storage class that provides information about their location and visibility. The storage class divides the portion of the program within which the variables are recognized.

auto

Auto is the default storage class.It is a local variable known only to the function in which it is declared.

static

Local variable which exists and retains its value even after the control is transferred to the calling function.

extern

Global variable known to all functions in the file.

register

Social variables which are stored in the register

Defining Symbolic Constants

A symbolic constant value can be defined as a preprocessor statement and used in the program as any other constant value. The general form of a symbolic constant is

# define symbolic_name value of constant

Valid examples of constant definitions are

# define marks 100
# define total 50
# define pi 3.14159

These values may appear anywhere in the program, but must come before it is referenced in the program.
It is a standard practice to place them at the beginning of the program.

Declaring Variable as Constant

The values of some variable may be required to remain constant through-out the program. We can do this by using the qualifier const at the time of initialization.

Example

 

Const int class_size = 40;

The const data type qualifier tells the compiler that the value of the int variable class _size may not be modified in the program.

Format Specifiers in C

%cThe character format specifier.
%dThe integer format specifier.
%iThe integer format specifier (same as %d).
%fThe floating-point format specifier.
%eThe scientific notation format specifier.
%EThe scientific notation format specifier.
%gUses %f or %e, whichever result is shorter.
%GUses %f or %E, whichever result is shorter.
%oThe unsigned octal format specifier.
%sThe string format specifier.
%uThe unsigned integer format specifier.
%xThe unsigned hexadecimal format specifier.
%XThe unsigned hexadecimal format specifier.
%pDisplays the corresponding argument that is a pointer.
%nRecords the number of characters written so far.
%%Outputs a percent sign.
Previous Home Next