Some Basic Conceptions of C programming Languge

Data Types:
There are five data types in C: character, integer, floating point, double floating point and valueless.
The sizes of these types are shown in below,
Type                                 Bit Width                                 Range
char                                        8                                      0     to     255
int                                          16                                    -32768    to    32767
float                                      32                                      3.4E-38   to    3.4E+38
double                                  64                                      1.7E-308   to   1.7E+308
void                                       0                                         valueless

To work with characters we need character type variable. So we have to declare a “char” type variable. Same case happen to work with integer type value such as 1, 8,-1,-8, 100, 587 etc. float and double are used to hold real numbers. Real numbers have both an integer and a frictional component.
Void has three uses. The first is use to declare explicitly a function as no returning no value;  the second is to declare explicitly a function as having no parameters; the third is to create generic pointers.


Commonly Used Conversion Characters for Data Input/Output:
Character                                                                         Meaning
c                                                               data item is a single character     
d                                                              data item is a decimal integer
f                                                               data item is a floating point value

s                                                              data item is a string followed by a whitespace
                                                                character (the null character \0 will automatically
                                                                be added at the end)          




Type Modifiers:
The basic data type (excepting type void) may have various modifiers preceding them. The modifier  is used to alter the meaning of the base type in various needs. The list of modifiers :
signed
unsigned
long
short

Declaration of variable:
When you are going to write a program, you should declare all variables before you use them. General form of declaration is
Data type     variable name;
Example:
                      int    I,   j,   k ;
                      char    s,  ch ;
                      double      balance,  profit ;
                      unsigned int    i ;


There are three basic places where variable will be declared: inside function, outside of all functions, or in the definition of the function parameters. These variables are called local variables, global variables, and formal parameters.

Compiler:
To compile your program you will need compiler. There are many c compiler, so you can chose any of them. But at the beginning Tc or code::blocks  will be useful. So I will tell you to collect one of them.
I have used code::blocks to describe following program in this blog. If you use Tc you can use  #inlude<conio.h>              clrscr();                       getch();
If you don’t use getch (), you will need to press ctrl+F5 to run your program otherwise ctrl+F9. To check error press F9. Remember: before you run your program save it in a hard drive to avoid loss you written code for any confliction during run. If you want to use getch(), write it before last curls-bracket  in the main function. You can use void in main function, if you do it, no need to return value to main function. But try to avoid it’s use. If you don’t use any data type before main, it will act as a int. So function will return a value. Okay you can understand all that I discussed when you do some practice.


Input and Output Library Function:           
Input                               Header File                      
scanf                                  stdio.h
fscanf                                 stdio.h
cscanf                                conio.h
sscanf                                 stdio.h
gets                                     string.h


Output                               Header File                       
printf                                  stdio.h
fprintf                               stdio.h
cprintf                                conio.h
sprintf                                 stdio.h
puts                                     string.h

There are more input output library function. We will work with some of them. At the beginning we will take input from standard I/O devices using scanf and write output using printf function.



Some Examples:
/*************** printf function ***************/
#include<stdio.h>

  int main( )
    {
      printf("C Programming Language");
      return 0;
         }



 /************** scanf function ***************/

#include<stdio.h>
  int main( )
     {
       int   x;
       printf("Enter a value: ");
       scanf("%d", &x);                                     // %d will take input a decimal value from I/O devices
       printf("\nGiven value is: %d", x);             // here %d will write a decimal value from x
       return 0;
     }
 




/*************** Variable within constant value *****************/

#include<stdio.h>
  int main( )
   {
     int a=100;
     printf("%d", a);
     return 0;
     }





/*************** Single character input ****************/

#include<stdio.h>

int main()
     {
         
char ch;
         printf(
"Enter a character: ");
         scanf(
"%c",&ch);     
         printf("\nGiven character is: %c",ch);
         
return 0;
        } 

              

No comments:

Post a Comment