-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrays_2.c
More file actions
51 lines (42 loc) · 1.3 KB
/
arrays_2.c
File metadata and controls
51 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
void printarray(int *l, int n);
// or we can define a array in function like these
void preintarr(int k[], int n);
int main(){
// Using Loops in ararys
int x[5];
printf("Enter marks of 5 students : \n");
for (int i = 0; i < 5; i++)
{
scanf("%d", &x[i]); // & is important here to assign values to pointers
}
for (int i = 0; i < 5; i++)
{
printf("The Value of index at %d is %d\n",i, x[i]);
}
// as per the upper program we can use loops to print values of index in a row
int cgpa[] = {9, 8, 8};
for (int i = 0; i < 3; i++)
{
printf("The value of array at index %d is %d\n", i, cgpa[i]);
}
// pointer arithmetic
int a = 32;
int *i = &a;
i++;
printf("The value of a is %d and i is %d",&a,i);
// Accessing arrays using pointers
int fk[0];
int *ptr = &fk[0];
ptr++;
*ptr; // will have 9 as its value
// we can pass a arrays to a function using these
int arr[10], n;
printarray(arr, n);
// Multi-dimensional arrays - an arrays can be 2 dimension/ 3 dimension/ n dimension
// a 2d arrays can be defined like this
int arr[3][2] = {{1,4}
{5,3}
{33,56}};
return 0;
}