Exercise on Array

Question

If an array is declared as, int a[9], what is its size in the memory?

click on below icon to see the answer.

36

Explanation: int is the datatype of array and size of int is 4. now total length of array is 9 (from index 0 to 8) and each index is an integer so total size will be 36 (data_type * array length).

Guess the output #2

int a[6] = {2, 7, 3, 1, 5, 9};
printf("%d", a[5] + 6);

Compiling this code produces following output. click on below icon to see the output.

15

Explanation: None.

Guess the output #3

#include <stdio.h>

int main()
{
    int array[5] = {1, 3, 2, 6, 5};
    int i = 3;

    if (array[i] == array[i+3]) {
        printf("True");
    } else {
        printf("False");
    }
    return 0;
}

Compiling this code produces following output. click on below icon to see the output.

TODO

Explanation: None.

Guess the output #4

#include <stdio.h>

int main()
{
	int arr[5]={5,7,3,1,2};

	arr[2] = arr[1];
	arr[1] = arr[3];
	arr[2] = arr[2] + arr[3];

	printf("%d, %d", arr[1], arr[2]);

	return 0;
}

Compiling this code produces following output. click on below icon to see the output.

TODO

Explanation: None.

Guess the output #5

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

printf("%d", &a[0][1] - &a[0][0]);

Compiling this code produces following output. click on below icon to see the output.

TODO

Explanation: None.

Guess the output #6

int array[2][3] = {{1, 2, 3}, {4, 5, 6}};
int i = 1;
int j = 0;

fun[i][j] = fun[j][i];
printf("%d, %d", fun[i][j], fun[j+1][i+1]);

Compiling this code produces following output. click on below icon to see the output.

TODO

Explanation: None.

Guess the output #7

int arr[2][2][2] = { { {1, 2}, {3, 4} }, {{5, 6}, {7, 8}}};
int calc;
int x = 0;

calc = arr[x][1][0] + arr[1][x + 1][0] + arr[0][1][x + 1];
printf("%d", calc);

Compiling this code produces following output. click on below icon to see the output.

TODO

Explanation: None.

Question

When we pass an array as an argument to a function in C, what actually gets passed?

click on below icon to see the Answer.

TODO

Explanation: None.

Question

What is the size of the array ‘arr’ if it is declared as, float arr[3][2][2]?

click on below icon to see the Answer.

TODO

Explanation: None.

Question

Which of the following statements about the array are true?

  1. The elements of the array have the same name and are located in separate memory locations.

  2. The expression ‘arr[1]’ represents the first element of the array

  3. The array ‘char ch[14]’ can store 15 elements including ch[0].

click on below icon to see the Answer.

TODO

Explanation: None.



©2023-2024 rculock.com