logging in or signing up arrays and pointers akash_4076 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 212 Category: Education License: All Rights Reserved Like it (3) Dislike it (0) Added: January 29, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... By: omkarachary (9 month(s) ago) PLSS SEND THIS PPT TO MY MAIL PLS Saving..... Post Reply Close Saving..... Edit Comment Close By: hardeep.singh920 (12 month(s) ago) Sir I require this presentation plz send me at hardeep.singh920@gmail.com Saving..... Post Reply Close Saving..... Edit Comment Close By: vini261985 (15 month(s) ago) Sir/Madam, As your presentation is more information. I would lik to download it to make a presentation for my students. Please send me a copy through mail or give me permission to download. Regards vini Saving..... Post Reply Close Saving..... Edit Comment Close Premium member Presentation Transcript ARRAYS : ARRAYS What is Array ? : What is Array ? Array is the collection of similar data type. The simplest type of data structure is a linear array or one dimensional array. By a linear array means a list of finite no. N of similar data elements. It referred as consecutive no. usually 1,2,3,4…n. If we choose the name A for the array , then the elements of A are denoted by subscript notation a1 , a2 , a3 , ………an Cont.. : Cont.. It also denoted by the parenthesis notation A(1), A(2), A(3), ……………………..A(N) Or by the bracket notation A[1], A[2], A[3],……A[K]..………..A[N] Where the number K in A[K] is called a subscript and A[K] is called a subscripted variable Example: Array : Example: Array A linear array STUDENT Consisting of the name of six students:- STUDENT Here STUDENT [1] denotes Rajesh STUDENT[1] STUDENTS[2] denotes Rakesh STUDENT[2] STUDENT[3] STUDENTS[3] denots Sanjay…. STUDENT[4] STUDENT[5] and so on. STUDENT[6] .. : .. Some common operation performed on arrays are: Creation of an array. Traversing an array. Insertion of new elements. Deletion of required element. Modification of an element. Merging of Arrays. Array delaration : Array delaration Representation of Array:- Datatype Array name [] Example:- Int marks[30] Entering data in to an array : Entering data in to an array For (i=0;i<=29;i++) { printf(“\n Enter Marks”); scanf(“%d”,&marks[i]); } Reading data from an Array : Reading data from an Array Suppose we want to find the average of marks For this we read data from array, add them and when all marks have been added up, the result is divided by 30, the no. of students, to get the average. for (i=0;i<=29;i++) sum = sum+marks[i]; Avg=sum/30; Printf(“average markes=%d”,Avg); Array Initailization : Array Initailization int num[6]={3,5,7,2,8,9} int n[]={2,5,2,8,4,9,0,4} float press[]={12.3,3.4,-5.6,34.2} 2-D Array : 2-D Array Syntax: Datatype ArrayName[][]; e.g. int mat[3][4]; Declare an Array : Declare an Array #include <stdio.h>#include <conio.h>int arr[5];void main() { arr[0]=10; arr[1]=20; arr[2]=30; arr[3]=40; arr[4]=50; clrscr(); printf( "At index 0,value is:%d," "\n At index 1,value is:%d," "\n At index 2,value is:%d," "\n At index 3,value is:%d," "\n At index 4,value is:%d\n", arr[0], arr[1], arr[2], arr[3], arr[4]); getch();} Copy an Array : Copy an Array #include <stdio.h>#include <conio.h>int main() { clrscr(); int array1[5]; int array2[5]; int i, j; array1[0]=10; array1[1]=20; array1[2]=30; array1[3]=40; array1[4]=50; for (i=0; i<5; i++) array2[i]=array1[i]; for (j=0; j<5; j++) printf("The value of %d=%d\n", j, array2[j]); getch(); return 0;} Length of array : Length of array #include <stdio.h> #include <conio.h> int array[6]={1,2,3,4,5,6}; void main() { clrscr(); int len=sizeof(array)/sizeof(int); printf("Length Of Array=%d",len); getch(); } POINTERS : POINTERS Slide 15: A pointer is a variable which holds the memory address. Any variable declared in a program has two components: Address of the variable Value stored in the variable. DECLARING POINTER VARIABLES : DECLARING POINTER VARIABLES Syntax: Data-type * pointer-variable; INITIALIZATION OF POINTER VARIABLES : INITIALIZATION OF POINTER VARIABLES Address of operator OR Reference Operator(&) int i=5; int *ptr=&i; POINTER TO A POINTER : POINTER TO A POINTER We can also declare a pointer variable to point to another pointer. That is pointer variable contains address of another pointer. POINTERS AND ARRAYS : POINTERS AND ARRAYS We know that the name of an array holds the address of the first element in that array. So we can make a conclusion that the name of an array is actually a pointer. OPERATIONS ON POINTERS : OPERATIONS ON POINTERS A pointer can be incremented(++) or decremented(--). Any integer can be added to or subtracted from pointer. One pointer can be subtracted from other. Operations that cannot be performed on pointers : Operations that cannot be performed on pointers Ptr1+ptr2 //addition not possible Ptr1*ptr2 //multiplication not possible Ptr1/3 //division not possible Ptr1/ptr2 DYNAMIC MEMORY MANAGEMENT : DYNAMIC MEMORY MANAGEMENT New Operator. Used to allocate memory at run-time and returns a pointer to that memory location. Int *ptr; Ptr=new int; THANK YOU : THANK YOU You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
arrays and pointers akash_4076 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 212 Category: Education License: All Rights Reserved Like it (3) Dislike it (0) Added: January 29, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... By: omkarachary (9 month(s) ago) PLSS SEND THIS PPT TO MY MAIL PLS Saving..... Post Reply Close Saving..... Edit Comment Close By: hardeep.singh920 (12 month(s) ago) Sir I require this presentation plz send me at hardeep.singh920@gmail.com Saving..... Post Reply Close Saving..... Edit Comment Close By: vini261985 (15 month(s) ago) Sir/Madam, As your presentation is more information. I would lik to download it to make a presentation for my students. Please send me a copy through mail or give me permission to download. Regards vini Saving..... Post Reply Close Saving..... Edit Comment Close Premium member Presentation Transcript ARRAYS : ARRAYS What is Array ? : What is Array ? Array is the collection of similar data type. The simplest type of data structure is a linear array or one dimensional array. By a linear array means a list of finite no. N of similar data elements. It referred as consecutive no. usually 1,2,3,4…n. If we choose the name A for the array , then the elements of A are denoted by subscript notation a1 , a2 , a3 , ………an Cont.. : Cont.. It also denoted by the parenthesis notation A(1), A(2), A(3), ……………………..A(N) Or by the bracket notation A[1], A[2], A[3],……A[K]..………..A[N] Where the number K in A[K] is called a subscript and A[K] is called a subscripted variable Example: Array : Example: Array A linear array STUDENT Consisting of the name of six students:- STUDENT Here STUDENT [1] denotes Rajesh STUDENT[1] STUDENTS[2] denotes Rakesh STUDENT[2] STUDENT[3] STUDENTS[3] denots Sanjay…. STUDENT[4] STUDENT[5] and so on. STUDENT[6] .. : .. Some common operation performed on arrays are: Creation of an array. Traversing an array. Insertion of new elements. Deletion of required element. Modification of an element. Merging of Arrays. Array delaration : Array delaration Representation of Array:- Datatype Array name [] Example:- Int marks[30] Entering data in to an array : Entering data in to an array For (i=0;i<=29;i++) { printf(“\n Enter Marks”); scanf(“%d”,&marks[i]); } Reading data from an Array : Reading data from an Array Suppose we want to find the average of marks For this we read data from array, add them and when all marks have been added up, the result is divided by 30, the no. of students, to get the average. for (i=0;i<=29;i++) sum = sum+marks[i]; Avg=sum/30; Printf(“average markes=%d”,Avg); Array Initailization : Array Initailization int num[6]={3,5,7,2,8,9} int n[]={2,5,2,8,4,9,0,4} float press[]={12.3,3.4,-5.6,34.2} 2-D Array : 2-D Array Syntax: Datatype ArrayName[][]; e.g. int mat[3][4]; Declare an Array : Declare an Array #include <stdio.h>#include <conio.h>int arr[5];void main() { arr[0]=10; arr[1]=20; arr[2]=30; arr[3]=40; arr[4]=50; clrscr(); printf( "At index 0,value is:%d," "\n At index 1,value is:%d," "\n At index 2,value is:%d," "\n At index 3,value is:%d," "\n At index 4,value is:%d\n", arr[0], arr[1], arr[2], arr[3], arr[4]); getch();} Copy an Array : Copy an Array #include <stdio.h>#include <conio.h>int main() { clrscr(); int array1[5]; int array2[5]; int i, j; array1[0]=10; array1[1]=20; array1[2]=30; array1[3]=40; array1[4]=50; for (i=0; i<5; i++) array2[i]=array1[i]; for (j=0; j<5; j++) printf("The value of %d=%d\n", j, array2[j]); getch(); return 0;} Length of array : Length of array #include <stdio.h> #include <conio.h> int array[6]={1,2,3,4,5,6}; void main() { clrscr(); int len=sizeof(array)/sizeof(int); printf("Length Of Array=%d",len); getch(); } POINTERS : POINTERS Slide 15: A pointer is a variable which holds the memory address. Any variable declared in a program has two components: Address of the variable Value stored in the variable. DECLARING POINTER VARIABLES : DECLARING POINTER VARIABLES Syntax: Data-type * pointer-variable; INITIALIZATION OF POINTER VARIABLES : INITIALIZATION OF POINTER VARIABLES Address of operator OR Reference Operator(&) int i=5; int *ptr=&i; POINTER TO A POINTER : POINTER TO A POINTER We can also declare a pointer variable to point to another pointer. That is pointer variable contains address of another pointer. POINTERS AND ARRAYS : POINTERS AND ARRAYS We know that the name of an array holds the address of the first element in that array. So we can make a conclusion that the name of an array is actually a pointer. OPERATIONS ON POINTERS : OPERATIONS ON POINTERS A pointer can be incremented(++) or decremented(--). Any integer can be added to or subtracted from pointer. One pointer can be subtracted from other. Operations that cannot be performed on pointers : Operations that cannot be performed on pointers Ptr1+ptr2 //addition not possible Ptr1*ptr2 //multiplication not possible Ptr1/3 //division not possible Ptr1/ptr2 DYNAMIC MEMORY MANAGEMENT : DYNAMIC MEMORY MANAGEMENT New Operator. Used to allocate memory at run-time and returns a pointer to that memory location. Int *ptr; Ptr=new int; THANK YOU : THANK YOU