Sunday, June 30, 2013

Data Types in C

In C we have many data types and each data type has its own range and its own specialization. Here is the table which gives you details about the data types and the range of each data type we are providing.

Variable Type
Keyword
Bytes Required
Range
Character
char
1
-128 to 127
Integer
int
2
-32768 to 32767
Short Integer
short
2
-32768 to 32767
Long Integer
long
4
-2,147,483,648 to 2,147,483,647
Unsigned character
unsigned char
1
0 to 255
Unsigned integer
unsigned int
2
0 to 65535
Unsigned short integer
unsigned short
2
0 to 65535
Unsigned long integer
unsigned long
4
0 to 4,294,967,295
Single Precision floating-point Number
float
4
1.2E-38 to 3.4E38
(Approx 7 digits precision)
Double precision floating-point number
double
8
2.2E-308 to 1.8E308
(Approx 19 digits precision)

Keywords in C

A keyword is a predefined word or a reserved word for a purpose. In C language there are totally 32 keywords. All the key words and their description is mentioned in the following tabular format. Please check the following table for a better understanding of each of the keyword.


Variables in C

A variable is a named data storage location in your computer's memory. By using a variable in the program, we are just referring to the data in our memory. To use the variables in our program, we must know how to create them. In creating a variable, there are certain conditions to be followed. They are

Conditions to setting Variable Names:

  • The name can contain letters, digits and the underscore character i.e., '_'.
  • The first character of the name must be a letter or an underscore.
  • If there is any change in the case of the letters, then they are treated as two different variables i.e., count  and Count are two different variables.
  • Keywords can't be a variable.

Saturday, June 29, 2013

Program without a Main Function

We would be wondering that we can write a C program without a main function. Generally we know that a C program cannot be executed without a main function. But we can execute it without main. Just try out the code below, it works fine even without a main function in it.

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf(” hello “);
}

Understanding a Program in C

Let us know more about a C program. A C program contains many components. If you observe the previous example, you can identify many things. Let us know more about what they are, why we have used them and how to use them.

Consider another example of C program which contains more components, than in the previous example and know what they are.

First C Program

Now, we are moving to our first program on C. This program just illustrates you to display the message Hello world,  but along with the program, we are going to understand the structure and the way we are supposed to write the program.

Example 1:


#include<stdio.h> 
main() 
{ 
printf("Hello World \n"); 
return 0; 
}

Friday, June 28, 2013

Creating a Program in C

While creating a program, we need to follow certain steps. These are the steps to be followed while creating any kind of C program.

  • Create the source code.
  • Compile the Source code.
  • Link the compiled code to create executable.
  • Run the executable code.