Monday, November 3, 2014

Variables in C Programming Language:

A variable is a memory location whose value can change (vary) during run-time, which is when a program is running. Most of the memory locations declared in a program are variables. 

In a program that inputs the radius of any circle and then calculates and outputs the circle’s area, a programmer would declare variables to store the values of the radius and area; doing this allows those values to vary while the program is running.

Variable Naming:

  • The name must begin with a letter.
  • The name can contain only letters, numbers, and the underscore character. No punctuation marks, spaces, or other special characters are allowed in the name.
  • The name cannot be a keyword. 
  • Names in C are case sensitive.

Variable Declaration:

Following syntax is used in declaration of the variables:
"Data_type Variable_name;"
Data Type defined the type of data that is to be stored in the variable while variable name can be anything according to the roles of naming variables.

Data Types: 

Following are different types of data type:
Basic Types:
They are arithmetic types and consists of the two types: (a) integer types and (b) floating-point types.
Enumerated types:
They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program.
The type void:
The type specifier void indicates that no value is available.
Derived types:
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.

Integer Data Type:

Following table gives you details about standard integer types with its storage sizes and value ranges:


To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.

Floating Point Data Type:

Following table gives you details about standard floating-point types with storage sizes and value ranges and their precision:

To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.

The Void Type:

The void type specifies that no value is available. It is used in three kinds of situations:

Function returns as void:
There are various functions in C which do not return value or you can say they return void. A function with no return value has the return type as void. For example void exit (int status);

Function arguments as void:
There are various functions in C which do not accept any parameter. A function with no parameter can accept as a void. For example, int rand(void);

Pointers to void :
A pointer of type void * represents the address of an object, but not its type. For example a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type.


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Popular Post

Geek Fixes. Powered by Blogger.

Translate

- Copyright © Geek Fixes -Amazing Wallpapers- Powered by Blogger - Designed by Adeel Sarwar