0% found this document useful (0 votes)
21 views

Arrays Output Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Arrays Output Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. #include<stdio.

h>

int main()

/* 2D array declaration*/

int disp[2][3];

/*Counter variables for the loop*/

int i, j;

for(i=0; i<2; i++)

for(j=0;j<3;j++)

printf("Enter value for disp[%d][%d]:", i, j);

scanf("%d", &disp[i][j]);

//Displaying array elements

printf("Two Dimensional array elements:\n");

for(i=0; i<2; i++)

for(j=0;j<3;j++)

printf("%d ", disp[i][j]);

if(j==2){

printf("\n");

}
return 0;

_____________________________________________________________________

2.#include <stdio.h>

int main()

int abc[5][4] ={

{0,1,2,3},

{4,5,6,7},

{8,9,10,11},

{12,13,14,15},

{16,17,18,19}

};

for (int i=0; i<=4; i++)

printf("%d ",abc[i]);

return 0;

3.#include<stdio.h>

int main()

{
int a[5] = {5, 1, 15, 20, 25};

int i, j, m;

i = ++a[1];

j = a[1]++;

m = a[i++];

printf("%d, %d, %d", i, j, m);

return 0;

_______________________________________________________________

4. #include<stdio.h>

int main()

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

int i, j;

static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

for(i=0; i<2; i++)

for(j=0; j<2; j++)

printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

*(*(i+p)+j), *(*(p+j)+i));

return 0;

}
__________________________________________________________

5. #include<stdio.h>

int main()

void fun(int, int[]);

int arr[] = {1, 2, 3, 4};

int i;

fun(4, arr);

for(i=0; i<4; i++)

printf("%d,", arr[i]);

return 0;

void fun(int n, int arr[])

int *p=0;

int i=0;

while(i++ < n)

p = &arr[i];

*p=0;

_________________________________________________________________________

6. #include<stdio.h>

void fun(int **p);

int main()

{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};

int *ptr;

ptr = &a[0][0];

fun(&ptr);

return 0;

void fun(int **p)

printf("%d\n", **p);

7.#include<stdio.h>

int main()

int arr[] = {0, 1, 2, 3, 4};

int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};

int **ptr=p;

ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*++ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

++*ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

return 0;
}

8.#include<stdio.h>

int main()

int a[3][4];

fun(a);

return 0;

9. #include<stdio.h>

int main()

int size, i;

scanf("%d", &size);

int arr[size];

for(i=1; i<=size; i++)

scanf("%d", arr[i]);

printf("%d", arr[i]);

return 0;

You might also like