Saturday, September 26, 2015

Hello program in C or First program in C

Now, after learning and understanding some basic concepts of the C programming we are going to write our first program of C. In this program we will combine variables, constants and keywords to make instructions. We will also look at the basic schema of a C program. In this program we will print "hello world" text.

#include<< stdio.h>>
#include<< conio.h>>
void main()
{
printf("hello world");
getch();
}

This is the first program of C.

In the first line we have defined a preprocessor (#). Which processes source code before code is passed to the compiler. In depth we will learn about the C preprocessor later.

Here, stdio.h (standard input output header file) is used for printf() function definition. printf() is used to print text.
conio.h file is used for getch() function definition.

main() is a function. A set of statement is known as function.
A function must always return a value. Here we have used void means this main() function will not return anything. If we want to return a integer value then we should use int on the place of void.

Important rules----
1.) Every statement should be separated by other statements.
2.) Every statement should be ends with ;.
3.) All statements should be written in small case letter.
4.) All statements must be written in same order in which we want to execute them.

Wednesday, September 9, 2015

Arithmetic Instructions in C

type of instruction in c programming


In C programming an arithmetic instruction contains a variable on left side of =(assignment operator) and variables names and constants on right side of =(assignment operator).

Syntax:-    variable=(combination of variables and constants connected by arithmetic operators)
                 a=b+c-d*e/f;

Variables and constants together known as operands.

Variables and constants who appears on the right side of assignment operator connected by arithmetic operators like +,-,*,/ etc.

On the time of execution of an arithmetic statement first operands operated upon by the arithmetical operators and then the result assigned to the variable on the left hand side of =(assignment operator).

These arithmetic statements can be of 3 types as follows :-

1. Integer mode- All operands are of integer type.
                             for ex.- int a,b,c;
                             a=b+c+2;
2. Real mode- All operands are of real type.
                        for ex.- float a,b,c;
                        a=b+c+1.0;
3. Mixed mode- Some of the operands are integer type and some of the operands are of real type.
                           for ex.- int a,b;
                           float c,d;
                           d=a+b-c+2+3.5;

Points to note:-

1. Only one variable on left side of assignment operator.
              for ex.- a=b+c;  // correct
                           a+b=c; //Incorrect

Wednesday, September 2, 2015

Integer & Real/Float Conversion in C


Integer and float conversion

If you would like to develop an effective C program. Then you should understand/know about some rules for implicit conversion of integer and real/floating value in C language.

Important rules are defined below:-

1. When we would perform an arithmetic operation between an integer and an integer operation will always produce an integer result.

For ex. 1-    int + int = int;
          5 + 4 = 9;

2. When we would perform an arithmetic operation between a real and a real operation will always produce a real result.

    For ex. 2-    real + real = real;
              5.0 + 4.0 = 9.0;

3. When we would perform an operation between an integer and a real then this operation will always produce a real result. 

  For ex. 3-   int + real = real;
            5 + 4.0 = 9.0;

Process for example 3 - first integer will be promoted to a real constant/variable then this operation would be performed and result would be real.

RELATED TOPIC FROM C PROGRAMMING LANGUAGES :-

Tuesday, September 1, 2015

Instruction Type in C


In C programming language 3 types of instructions are available. These are as follows:-

1. Type declaration Instruction      
3. Control Instruction

1. Type Declaration Instruction:-


In C programming language every variable which is used in the program must be declared before its use in any further statements.
So, this instruction is used to declare the type of a variable being used in the program.

For ex.:- If we have to use "a" as a variable typed integer then we should declare it before using it as-
             int a;

Note-1 When we declare any variable at that time we are also eligible to initialize this variable.

For ex.  int i=5,j=7;
             float a=5.5;

Note-2 when we declare and initialize variables together the issue of ordering occurs.
Sometime order of declaration matters and sometime not.

For ex.   1) int i=10,j=25;                
   int j=25,i=10;
             here,order of variable declaration doesn't matter.
          2) float a=1.5,b=a+3.1;
              float b=a+3.1,a=1.5;

Wednesday, August 12, 2015

C Variables and Rules for Variable name

Variables :-

An entity that may change is called Variable.






For example:- a=3;
                         a=5; Here the value of 'a' is changed from 3 to 5. 'a' is a variable.

1. As we know that every value store in memory at specific location.

2. If we have to call that value we should remember the location. But it is difficult to remember. So, we give that location a name which can be remember easily.

3. These name of location in memory are known as variable name.Means variable names are the names given to location in memory.

4. Values at these location can be integer, real or character constants.

5. Specific type of variable can store  the specific type of constant.

For example:- An integer variable  can only store an integer constant.
                        int a;
                        a=2;

                        An real variable  can only store an real constant.
                        float b;
                        b=5.5;

                        An character variable  can only store an character constant.
                        char c;
                        c='a';





Rules for Constructing Variable Name:-

1. Length of the variable name is depends upon the compiler type. Some compiler allows variable name's length up-to 247 character. But it would be safer to use the rule of 31 character.

2. In variable name first character must be an alphabet or underscore.

3. There is no commas or blanks are allowed within a variable name.

4. In variable name other than underscore no special symbols can be used.

5. Keywords used in C programming cannot be used as a variable name.

For example:- int simple;
                         int sim_ple;
                         int _simple;

Wednesday, July 15, 2015

Keywords in C @ concept of programming

reserved word in c programming,how many keyword in c

1. Words which are reserved by compiler are known as Keywords.

2. We cannot use these reserved words as a variable name because if we will do this ,we tried to change the meaning of that keyword which is not allowed by the compiler.

3. So, user cannot change the meaning of any keyword.

4. As all we know c programming is a case sensitive programming language so, every keyword must be written in lowercase.

5. In c programming mainly 32 keywords are available. List of all keywords in c language is given below :-

Keywords In C Programming
autodoubleintstruct
breakelselongswitch
caseenumregistertupedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile




















6.Apart from the above mentioned keywords some other compiler vendors like micosoft etc. provide their own keywords. Some of them extended keywords are given below-

Extended keywords In C Programming
asmnearfarpascal intrrupthugecdecl








RELATED TOPIC FROM C PROGRAMMING LANGUAGES-




1.What is c programming language?
2.Why should we learn c programming before migrating to high level languages like c++ or java?
3.Character set in C programming language.
4.Constant in C programming language.

Monday, April 27, 2015

Constant in C Programming Language and Rules for Constructing Constant


variable and constant in c programming,primary constant,secondary constant,integer,real,float,character,array,structure,pointer,union,enum and rules for constructing constant


Constant - An entity that does not change known as constant.

                            In c programming constant can be divided into 2 major categories :

                            1. Primary Constant :-

                                Here primary constant is further categorized into 3 types.
                                
                                1.Integer
                                2.Real
                                3.Character




                            2. Secondary Constant :-

                                Secondary constant is also further divided into below categories.
                                
                                1. Array
                                2. Pointer
                                3. Structure
                                4. Union 
                                5. Enum




In C programming,there are some rules for constructing constant:

1. Rules for constructing integer constant:

Rules for constructing integer constant are as follows:

1. An integer constant must contain at least one digit.
2. An integer must not have a decimal point
3. An integer can be either positive or negative.
4. If an integer does not precedes any sign it is assumed to be positive.
5. Commas and blanks are not allowed.
6. The range of an integer constant depends upon the type of compiler.
             For Example- 
                                   For gcc and visual studio compiler -2147483648 to +2147483647
                                  For turbo c or turbo c++ compiler is -32768 to 32767.






2. Rules for constructing real constant:-





Also known as floating point constant .
 
             These constant have 2 forms :-
A) Fractional form
B) Exponential form      

A) Rules for constructing fractional form real constant:-

1. Constant must have at least one digit.
2. Constant must have a decimal point.
3. Can be either positive or negative .
                4. If no sign precedes it is assumed to be positive.
5. Commas and blanks are not allowed.
For ex. +325.24 

B) Rules for constructing exponential form real constant:-

Exponential real constant represented in 2 parts.
1. First part before "e" known as mantissa.
2. Part after "e" known as exponent.
For ex. 0.22e4

a) Both the parts mantissa and exponent should be separated by a alphabet "e" or "E".
b) Mantissa part may have a positive or negative sign default will be positive.
c) Exponent part must have at least one digit which must be positive or negative integer,        default will be positive.
d) Range of exponential form is -3.4e38 to 3.4e38

3. Rules for constructing character constant:-

a) a character constant contains a single alphabet,a single digit or a single special symbol enclosed within single inverted commas.
b) both inverted commas should point to left.