wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Arrays in C (II yr 02.07.2020)

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.

#include <stdio.h>

int main()

{

int arr[5];

// Assume base address of arr is 2000 and size of integer is 32 bit

printf("%u %u", arr + 1, &arr + 1);

return 0;

}


What is the o/p of the program?

a)

2004 2020

b)

2004 2004

c)

2004 Garbage value

d)

The program fails to compile because Address-of operator cannot be used with array name

2.

#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);

}

What is the o/p of the program?

a)

4

b)

3

c)

2

d)

1

3.

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address?

1:When array name is used with the sizeof operator.

2:When array name is operand of the & operator.

3:When array name is passed to scanf() function.

4:When array name is passed to printf() function.

a)

1

b)

1,2

c)

2

d)

2,4

4.

Which of the following statements are correct about an array?

1:The array int num[26]; can store 26 elements.

2:The expression num[1] designates the very first element in the array.

3:It is necessary to initialize the array at the time of declaration.

4:The declaration num[SIZE] is allowed if SIZE is a macro.

a)

1

b)

1,4

c)

2,4

d)

2,3

5.

#include <stdio.h>

void main()

{

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

int *p = a;

printf("%p\t%p", p, a);

}


In Output,

a)

Same address is printed

b)

Different address is printed

c)

Compile time error

d)

Nothing

6.

#include <stdio.h>

void foo( int[] );

int main()

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

foo(ary);

printf("%d ", ary[0]);

}

void foo(int p[4])

{

int i = 10;

p = &i;

printf("%d ", p[0]);

}

Output of the Program?

a)

10 10

b)

Compile time error

c)

10 1

d)

Undefined behaviour

7.

Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?

a)

foo[6];

b)

foo[7];

c)

foo(7);

d)

foo;

8.

Which of the following gives the memory address of the first element in array foo, an array with 100 elements?

a)

foo[0];

b)

foo;

c)

&foo;

d)

foo[1];

9.

What is the index number of the last element of an array with 29 elements?

a)

29

b)

28

c)

0

d)

Programmer-defined

10.

Which of the following is a two-dimensional array?

a)

array anarray[20][20];

b)

int anarray[20][20];

c)

int array[20, 20];

d)

char array[20];