SlideShare a Scribd company logo
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
t
                                                               y
         Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.


                                                               C
                                       Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS ARRAYS


                                   2
Introduction
• Arrays
    – Group of consecutive memory locations.
    – Each memory location is known as element.
    – The name and type of each element is same.
    – Declare an array with the name and size.
       • data_type array_name[size];
         int a[5];
         char name[20];

3
Introduction…
        int a[5];
• Above statement creates an array of…
     • Data type: integer
                                         First element at 0th position
     • Array name: a
     • Array size : 5
                                                           Memory
• Counting starts from 0.
                     0   1   2   3       4




                                     4
Introduction…
• Format to access an element.
  – array_name[position];
    int a[5];
    Printf(“%d”,a[3]);



                  0   1   2   3       4




                                  5
Initialization of Array
• Initialize at the time of declaration.
     int a[5] = { 10, 20, 30, 40, 50 };
• Initialization all elements with zero.
     int a[5] = { 0 };
• Initialize all element and define it’s size.
     int a[ ] = { 10, 20, 30, 40, 50 };
• 5 values means 5 elements in array a.
                               6
Initialization of Array…
• All the elements can be initialized as the
  normal variables.
        int a[5];
        a[0] = 10;
        a[1] = 20;
        a[2] = 30;
        a[3] = 40;
        a[4] = 50;


                      7
Initialization of Array…
• Initialize all elements using loops.
         for (int i=0; i<=4; i++)
         {
                   scanf(“%d”,&a[ i ]);
         }




                             8
Character Arrays
• Character arrays can be initialized using string
  literals (Double quotes).
          char c* + = “hello”;
  – “hello” is a string.
  – String terminates with the null character ‘0’.
  – String “hello” has 6 elements.
  – We can also initialize it with
         char c* + = ,‘h’ , ’e’ , ’l’ , ’l’ , ’o’, ‘0’-;
                                  9
More about arrays
• Array name is the address of the first element
  of the array.
         printf(“%u”,&a[0]);
         printf(“%u”, a);
• Both statements will produce the same result.




                            10
More about arrays
• In case of character type array we can scan the
  contents by using array name only.
         scanf(“%s”,c);
  – Reads characters until whitespace encountered.
  – May go beyond the size of an array.




                          11
Multi-Dimensional Arrays
• Two-Dimensional arrays
     – Assume it as a table of row and column.
     – First specify Row and then column.
           int a[2][3];
     – Array a have 2 rows and 3 columns.

     6
     5
     4
     3
     2
     1          [0][0]        [0][1]        [0][2]
                [1][0]        [1][1]        [1][2]


12
Two-Dimentional Array…
      int a[2][3];
• Array a contains 2 rows and 3 columns, that
  means it has 2 * 3 = 6 elements.
• These elements will store in consecutive
  memory locations.          a[1][2]
                             a[1][1]
                             a[1][0]
                             a[0][2]
                             a[0][1]
                             a[0][0]




                      13
Initialization
int a[2][3] = { {1,2,3} {10,20,30} };

   1                2               3
   10               20             30

int a[2][3] = { {1,2} {10} };

   1                2               0
   10               0               0


                         14
Accessing Elements
for(i=0; i<=1; i++)
{
         for(j=0; j<=2; j++)
         {
                  printf(“%d”,a[i][j]);
         }
}

printf(“%d”,a[1][2]);


                        15
Mind Bend
• Write a program which performs the following
  tasks:
  – Initialize an integer array of 10 elements.
  – Print array in a well formatted way.
  – Multiply each element of array by 3.
  – Print the array elements.
• Write a program to pick up the largest and
  smallest number from any 3 x 3 array.
                            16
Mind Bend
• Write a program to add two 5 x 5 matrix.
• Write a program to initialize an array of 6 x 6
  by keyboard and copy elements of an array to
  the another 4 x 9 array.                1
                                          5
                                               2
                                               6
                                                    3
                                                    7
                                                         4
                                                         8

       1    2    3    4    5    6         9    10   11   12

       7    8    9    10   11   12        13   14   15   16
                                          17   18   19   20
       13   14   15   16   17   18
                                          21   22   23   24
       19   20   21   22   23   24
                                          25   26   27   28
       25   26   27   28   29   30
                                          29   30   31   32
       31   32   33   34   35   36
                                          33   34   35   36


                                     17
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              For any problem in this tutorial mail me at
                    yogendra@learnbywatch.com
                        with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com


Keep Watching Keep Learning

NEXT IS POINTERS

                                    18

More Related Content

PPT
Mesics lecture 8 arrays in 'c'
PPT
Arrays Class presentation
PDF
Arrays in Java
PPTX
Array in Java
PPTX
Array in c++
PPTX
Java arrays
PPT
Chap09
Mesics lecture 8 arrays in 'c'
Arrays Class presentation
Arrays in Java
Array in Java
Array in c++
Java arrays
Chap09

What's hot (20)

PPTX
Arrays In C++
PPTX
PPTX
Arrays In C Language
PPT
Arrays Basics
PPTX
Arrays in c
PPT
C++ Arrays
PPTX
Presentation on array
PPTX
arrays of structures
PPTX
Arrays in C++
ODP
C++ arrays part1
PDF
Lecture17 arrays.ppt
PPTX
Array in C
PPTX
Array in c programming
PPTX
Introduction to Array ppt
PPT
Array in c
PPTX
Array,MULTI ARRAY, IN C
PPTX
A Presentation About Array Manipulation(Insertion & Deletion in an array)
PPTX
Array in c language
PPTX
Arrays in c
PPT
Lecture 2a arrays
Arrays In C++
Arrays In C Language
Arrays Basics
Arrays in c
C++ Arrays
Presentation on array
arrays of structures
Arrays in C++
C++ arrays part1
Lecture17 arrays.ppt
Array in C
Array in c programming
Introduction to Array ppt
Array in c
Array,MULTI ARRAY, IN C
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Array in c language
Arrays in c
Lecture 2a arrays
Ad

Similar to Arrays (20)

PDF
7. arrays
PDF
Arrays and library functions
PDF
arraysfor engineering students sdf ppt on arrays
PPTX
Module_3_Arrays - Updated.pptx............
PPTX
INDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptx
PPT
Basics of Data structure using C describing basics concepts
PPTX
Arrays in C language
PPTX
Arrays & Strings
PPTX
Data structure.pptx
PPT
PPTX
Arrays
PPTX
Arrays.pptx
PPTX
COM1407: Arrays
PDF
C++ Chapter III
PPT
PPTX
Arrays basics
PPT
Array THE DATA STRUCTURE. ITS THE STRUCT
PDF
Plc (1)
PPTX
Module 4- Arrays and Strings
7. arrays
Arrays and library functions
arraysfor engineering students sdf ppt on arrays
Module_3_Arrays - Updated.pptx............
INDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptx
Basics of Data structure using C describing basics concepts
Arrays in C language
Arrays & Strings
Data structure.pptx
Arrays
Arrays.pptx
COM1407: Arrays
C++ Chapter III
Arrays basics
Array THE DATA STRUCTURE. ITS THE STRUCT
Plc (1)
Module 4- Arrays and Strings
Ad

More from Learn By Watch (20)

PPTX
Tutorial 9 fm
PPTX
Phase modulation
PPTX
Demodulation of fm pll detector
PPTX
Demodulation of fm slope and balanced slope detector
PPTX
In direct method of fm generation armstrong method
PPTX
Direct method of fm generation hartley oscillator method
PPTX
Carson's rule
PPTX
Spectrum and power of wbfm
PPTX
Narrow band frequency modulation nbfm
PPTX
General expression of fm signal
PPTX
Angle modulation
PPTX
Frequency division multiplexing
PPTX
Vsb modulation
PPTX
Demodulation of ssb synchronous detector
PPTX
Generarion of ssb phase discrimination method
PPTX
Generarion of ssb frequency discrimination method
PPTX
Ssb modulation
PPTX
Demodulation of dsb sc costas receiver
PPTX
Quadrature carrier multiplexing qam
PPTX
Demodulation of am synchronous detector
Tutorial 9 fm
Phase modulation
Demodulation of fm pll detector
Demodulation of fm slope and balanced slope detector
In direct method of fm generation armstrong method
Direct method of fm generation hartley oscillator method
Carson's rule
Spectrum and power of wbfm
Narrow band frequency modulation nbfm
General expression of fm signal
Angle modulation
Frequency division multiplexing
Vsb modulation
Demodulation of ssb synchronous detector
Generarion of ssb phase discrimination method
Generarion of ssb frequency discrimination method
Ssb modulation
Demodulation of dsb sc costas receiver
Quadrature carrier multiplexing qam
Demodulation of am synchronous detector

Arrays

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2. t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS ARRAYS 2
  • 3. Introduction • Arrays – Group of consecutive memory locations. – Each memory location is known as element. – The name and type of each element is same. – Declare an array with the name and size. • data_type array_name[size]; int a[5]; char name[20]; 3
  • 4. Introduction… int a[5]; • Above statement creates an array of… • Data type: integer First element at 0th position • Array name: a • Array size : 5 Memory • Counting starts from 0. 0 1 2 3 4 4
  • 5. Introduction… • Format to access an element. – array_name[position]; int a[5]; Printf(“%d”,a[3]); 0 1 2 3 4 5
  • 6. Initialization of Array • Initialize at the time of declaration. int a[5] = { 10, 20, 30, 40, 50 }; • Initialization all elements with zero. int a[5] = { 0 }; • Initialize all element and define it’s size. int a[ ] = { 10, 20, 30, 40, 50 }; • 5 values means 5 elements in array a. 6
  • 7. Initialization of Array… • All the elements can be initialized as the normal variables. int a[5]; a[0] = 10; a[1] = 20; a[2] = 30; a[3] = 40; a[4] = 50; 7
  • 8. Initialization of Array… • Initialize all elements using loops. for (int i=0; i<=4; i++) { scanf(“%d”,&a[ i ]); } 8
  • 9. Character Arrays • Character arrays can be initialized using string literals (Double quotes). char c* + = “hello”; – “hello” is a string. – String terminates with the null character ‘0’. – String “hello” has 6 elements. – We can also initialize it with char c* + = ,‘h’ , ’e’ , ’l’ , ’l’ , ’o’, ‘0’-; 9
  • 10. More about arrays • Array name is the address of the first element of the array. printf(“%u”,&a[0]); printf(“%u”, a); • Both statements will produce the same result. 10
  • 11. More about arrays • In case of character type array we can scan the contents by using array name only. scanf(“%s”,c); – Reads characters until whitespace encountered. – May go beyond the size of an array. 11
  • 12. Multi-Dimensional Arrays • Two-Dimensional arrays – Assume it as a table of row and column. – First specify Row and then column. int a[2][3]; – Array a have 2 rows and 3 columns. 6 5 4 3 2 1 [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] 12
  • 13. Two-Dimentional Array… int a[2][3]; • Array a contains 2 rows and 3 columns, that means it has 2 * 3 = 6 elements. • These elements will store in consecutive memory locations. a[1][2] a[1][1] a[1][0] a[0][2] a[0][1] a[0][0] 13
  • 14. Initialization int a[2][3] = { {1,2,3} {10,20,30} }; 1 2 3 10 20 30 int a[2][3] = { {1,2} {10} }; 1 2 0 10 0 0 14
  • 15. Accessing Elements for(i=0; i<=1; i++) { for(j=0; j<=2; j++) { printf(“%d”,a[i][j]); } } printf(“%d”,a[1][2]); 15
  • 16. Mind Bend • Write a program which performs the following tasks: – Initialize an integer array of 10 elements. – Print array in a well formatted way. – Multiply each element of array by 3. – Print the array elements. • Write a program to pick up the largest and smallest number from any 3 x 3 array. 16
  • 17. Mind Bend • Write a program to add two 5 x 5 matrix. • Write a program to initialize an array of 6 x 6 by keyboard and copy elements of an array to the another 4 x 9 array. 1 5 2 6 3 7 4 8 1 2 3 4 5 6 9 10 11 12 7 8 9 10 11 12 13 14 15 16 17 18 19 20 13 14 15 16 17 18 21 22 23 24 19 20 21 22 23 24 25 26 27 28 25 26 27 28 29 30 29 30 31 32 31 32 33 34 35 36 33 34 35 36 17
  • 18. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS POINTERS 18