SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C LanguageSurbhi Yadav
 
Presentation on array
Presentation on array Presentation on array
Presentation on array topu93
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppteShikshak
 
Array in c programming
Array in c programmingArray in c programming
Array in c programmingMazharul Islam
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN Cnaveed jamali
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)Imdadul Himu
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 

Mais procurados (20)

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Array
ArrayArray
Array
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Array in C
Array in CArray in C
Array in C
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array in c
Array in cArray in c
Array in c
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 

Semelhante a Arrays (20)

Array i imp
Array  i impArray  i imp
Array i imp
 
arrays
arraysarrays
arrays
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
 
CS.3.Arrays.pdf
CS.3.Arrays.pdfCS.3.Arrays.pdf
CS.3.Arrays.pdf
 
Mit6 094 iap10_lec04
Mit6 094 iap10_lec04Mit6 094 iap10_lec04
Mit6 094 iap10_lec04
 
Lec4
Lec4Lec4
Lec4
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Array notes
Array notesArray notes
Array notes
 
4.ArraysInC.pdf
4.ArraysInC.pdf4.ArraysInC.pdf
4.ArraysInC.pdf
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 

Mais de Learn By Watch

Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detectorLearn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorLearn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong methodLearn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodLearn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfmLearn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfmLearn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signalLearn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexingLearn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorLearn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodLearn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodLearn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverLearn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qamLearn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detectorLearn By Watch
 

Mais de Learn By Watch (20)

Tutorial 9 fm
Tutorial 9 fmTutorial 9 fm
Tutorial 9 fm
 
Phase modulation
Phase modulationPhase modulation
Phase modulation
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
 
Carson's rule
Carson's ruleCarson's rule
Carson's rule
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
 
Angle modulation
Angle modulationAngle modulation
Angle modulation
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
 
Vsb modulation
Vsb modulationVsb modulation
Vsb modulation
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
 
Ssb modulation
Ssb modulationSsb modulation
Ssb modulation
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
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