Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Pointers Vs. Multi-dimensional Arrays 

C Programming Questions and Answers – Pointers Vs. Multi-dimensional Arrays

 

1.int a[10][20]; which is true for a

a) a is true two-dimensional array

b) 200 int-sized locations have been set aside

c) The conventional rectangular subscript calculation 20 * row + col is used to find the element a[row, col] d) All of the mentioned

View Answer

 

Answer:d

2.int *b[10]; which is true for b

a) The definition only allocates 10 pointers and does not initialize them

b) Initialization must be done explicitly

c) Both a and b

d) Error

View Answer

 

Answer:c

3.What is the output of this C code?

 

#include <stdio.h>

void main()

{

char a[10][5] = {“hi”, “hello”, “fellows”};

printf(“%s”, a[2]);

}

a) fellows

b) fellow

c) fello

d) fell

View Answer

 

Answer:c

4.What is the output of this C code?

 

#include <stdio.h>

void main()

{

char a[10][5] = {“hi”, “hello”, “fellows”};

printf(“%p\n”, a);

printf(“%p”, a[0]);

}

a) Same address is printed

b) Different address is printed

c) hello

d) hi hello fello

View Answer

 

Answer:a

5.What is the output of this C code?

 

#include <stdio.h>

void main()

{

char a[10][5] = {“hi”, “hello”, “fellows”};

printf(“%d”, sizeof(a[1]));

}

a) 2

b) 4

c) 5

d) 10

View Answer

 

Answer:c

6.What is the output of the code given below?

 

#include <stdio.h>

int main()

{

char a[1][5] = {“hello”};

printf(“%s”, a[0]);

return 0;

}

a) Compile time error

b) hello

c) Undefined behaviour

d) hellon

View Answer

 

Answer:c

7.What is the output of the code given below?

 

#include <stdio.h>

int main()

{

char *a[1] = {“hello”};

printf(“%s”, a[0]);

return 0;

}

a) Compile time error

b) hello

c) Undefined behaviour

d) hellon

View Answer

 

Answer:b

8.Which of the following statements are true?

Pointer to Array

Multi-dimensional array

a) P are static, Q are static

b) P are static, Q are dynamic

c) P are dynamic, Q are static

d) P are dynamic, Q are dynamic

View Answer

 

Answer:c

9.What is the output of this C code (considering sizeof char is 1 and pointer is 4)?

#include <stdio.h>

int main()

{

char *a[2] = {“hello”, “hi”};

printf(“%d”, sizeof(a));

return 0;

}

a) 9

b) 4

c) 8

d) 10

View Answer

Answer:c

 

10.What is the output of this C code?

#include <stdio.h>

int main()

{

char a[2][6] = {“hello”, “hi”};

printf(“%d”, sizeof(a));

return 0;

}

a) 9

b) 12

c) 8

d) 10

View Answer

 

Answer:b

11.What is the output of this C code?

 

#include <stdio.h>

int main()

{

char a[2][6] = {“hello”, “hi”};

printf(“%s”, *a + 1);

return 0;

}

a) hello

b) hi

c) ello

d) ello hi

View Answer

 

Answer:c

12.What is the output of this C code?

 

#include <stdio.h>

int main()

{

char *a[2] = {“hello”, “hi”};

printf(“%s”, *(a + 1));

return 0;

}

a) hello

b) ello

c) hi

d) ello hi

View Answer

 

Answer:c

13.Advantage of a multi-dimension array over pointer array.

a) Pre-defined size.

b) Input can be taken from user.

c) Faster Access.

d) All of the mentioned

View Answer

 

Answer:d

14.Which of the following operation is possible using a pointer char?

(Assuming declaration char *a;)

a) Input via %s

b) Generation of multidimensional array

c) Changing address to point at another location

d) All of the mentioned

View Answer

 

Answer:c

15.Comment on the following two operations?

int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1

int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

a) 1 will work, 2 will not

b) 1 and 2, both will work

c) 1 won’t work, 2 will work

d) Neither of them will work

View Answer

 

Answer:c

16.Comment on the following two operations?

int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1

int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

a) 1 works, 2 doesn’t

b) 2 works, 1 doesn’t

c) Both of them work

d) Neither of them work

View Answer

 

Answer:d

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button