Saturday, 13 July 2019

What is array?

Arrays a type of data structure that can store a fixed-size sequential collection of elements of the same type.
We can't take any array with a half of data types.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

The bracket [  ] denotes to the compiler that for an array.

The declaration of array -

Data_type <array name>[expression]
Ex-
         Int array[10]

Intialization of array
 
Int array[10]={1,5,8,9,6,0,3,4,2,7}

Types of array -

Arrays are important to C and should need a lot more attention. The following important concepts related to array should be clear to a C programmes.

 

Multidimensional arrays

C supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.

Twodimensional array

The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of size [x][y], you would write something as follows:

type arrayName [ x ][ y ];


 

Where type can be any valid C data type and arrayName will be a valid C identifier. A two-dimensional array can be considered as a table which will have x number of rows and y number of columns.

What is pointers?

A pointer is a variable which denotes the address in the memory of another variable. 
When a pointer is declared it does not point anywhere. You must set it to point somewhere before you use it. 

#include <stdio.h>

int main ()

{

int var1;

char var2[10];

printf("Address of var1 variable: %x\n", &var1 );

printf("Address of var2 variable: %x\n", &var2 );

return 0;

}

 

include <stdio.h>

in the above code is compiled and executed, it produces the following result:

Address of var1 variable: bff5a400

Address of var2 variable: bff5a3f6




Application of pointer-

Accessing data by their address for example
Parameters are argument of function main. 

Null Pointer-

It is always a good practice to assign a NULL value to a pointer variable in case you do not have an exact address to be assigned. This is done at the time of variable declaration. A pointer that is assigned NULL is called a null pointer.

The NULL pointer is a constant with a value of zero defined in several standard libraries. Consider the following program:

 

#include <stdio.h>

int main ()

{

int *ptr = NULL;

printf("The value of ptr is : %x\n", ptr );

return 0;

}

 

When the above code is compiled and executed, it produces the following result:

 

The value of ptr is 0

Monday, 3 June 2019

What is operator?

Operator-
An operator is symbol which       
used to operate variables and data.
Operator symbols helps to the users for applying the commonds to complete mathematical manipulations.
C has many operators--
1 Arithmatic operator
2 Relational operator
3 Logic operator
4 Assignment operator
5 Increment &decrement operator
6 Bitwise operator

1.Arithmetic operator-:
       
In this operator mostly mathematical symbols like plus, minus etc.
Ex.
   Operator                       work of operator
       +                              For addition
        -                              For subtraction
        *                              For multiplication
         /                             For division
        %                (modulo) for find reminder

2.Relational operator-:

These types of operator shows the relationship among to the functions.

Operator                        work of operator
      <                                is less than
      <=                       is less than or equal to
      >                                is greater than
      >=                  is greater than or equal to
      ==                              is equal to
      !=                                is not equal to

3.Logic operator-:

Operator                        work of operator
   &&                                     logic AND
     ||                                      logic OR
     !                                        logic NOT

4. Assignment operator-:

Operator                        work of operator
    =                                   for assign a value
    *=                              multiply and assign
    /=                             divide and assign
   %=                              moduls and assign
    +=                              add and assign
     -=                              substrct and assign
5.Increment and Decrement operator-:

Operator                        work of operator
   ++                                   increment
    --                                    decrement

6.Bitwise operator-:

Operator                        work of operator

    &                                     AND
     |                                     Inclusive OR
     ^                                    Exclusive OR
    <<                                    Shift left
    >>                                    Shift right
     ~                                 One's compliment

Saturday, 1 June 2019

How to write a program to add two numbers?


#include<stdio.h>
#include<conio.h>
void main()
{
  int a, b, sum;
  clrscr();
   printf("Enter your two numbers =");
  scanf("%d%d",&a,&b);
   sum=a+b;
   printf ("The sum of numbers=%d",sum);
  getch();
}
Output is--
Enter your two numbers=5
                                            9
sum of two numbers=14

Friday, 31 May 2019

How to write a c program?

After writing any program first we know about what is program? And
What are the essential rules for writing a program in c?

Program-: The collection or group of instructions & informations is called a program.

These are the some important rules for the writing a program in c--

1. Never use capital letters.
2. Use ; in last of statement.
3. Use variable to define parameters
   a, x, y, p, q.... ✔
   ax, bx, xy...... ✔
   x1, x2, x5...... ✔
   3x, 6x, 2x......❌
4. Header file should be included.
     Two header files must be included
First-
         #include<stdio.h>
    Stdio means standard input/output.
   Where .h is the extension of header file.
    The work of this header file is --
    In this files Printf() ; and scanf(); are         executed.
Second-
              #include<conio.h>
      Conio means console input/output.
       The work of this header file is--
      In this file getch() ; and clrscr();         are executed.
. The purpose of getch(); is to hold the output on the console.
. The purpose of clrscr(); is to clear all the trash data on the console.

5. If we take integer type value then we have to use
         Int
        0-9
        %d
     If we take float type value then we have to use
          float
           0.1,.57,.886
          %f
If we take charecter type value then we have to use
           Char
            a-z
             %s

6. Program will start from main().
7. After main(); start the program with curly braces {_}.
8.

Let's take an example of c program---
      #include<stdio.h>    
      #include<conio.h>
        main()
          {
             printf("my name is A.");
             getch();
           }
Output of this program is
   my name is A.
 

Note-:#<include> is pre processor command. This statement tells the pre- processors to include the information contained in the file stdio.h before it is past for the compilation.

main() - main is a special function name. Every c program has main function somewhere in the program. This function will be executed first when the program is run.
           &- is used for the address of the          value where stored.
            If you are writing a c program in turbo c software then
    To compile your program press Alt+f9
      To run the program press Ctrl+f9.