Monday, January 11, 2016

Variables

Void Type

Void type is defined using keyword 'void'. It's used to represent absence of data. For example, if a functions is declared with 'void' return type, it means that function doesn't return any values. But you cannot define a variable with 'void' type, program will not compile. You can declare void pointers though. 
Variables
In C programs, sometimes you may need to store some values so that you can later do some calculation or operation on the stored values. To hold these values we need variables. The variable can be considered as a type of identifiers that are used to represent some type of value or information in a designated portion of a program. A variable can be assigned different values in the course of its life span, i.e. the value stored in a variable may change. However, the type of data associated with a variable can never be changed.
Variable declaration
Declaration means associating a variable with some data type. Declaring variable will enforce that the variable can only represent values of already specified data types. A declaration has a specific format. Let’s consider following declaration as an example.
int number;
By this declaration, we are specifying that the number is a variable of data type integer. Until now, the variable number does not contain the value we want. The values can be assigned to the variable as follows

number = 6;
This is called assigning a value to a variable. Variable declaration and assignment can be merged as shown in the example below
float price = 1234.50;

Character and character strings

In C, for single character we have a data type char, but for storing multiple characters, like a word, there is no specific data type provided. So, unlike other programming languages like C++, Java etc., C doesn’t have string data types. Strings are often stored as a character array in C.

No comments: