github

Made bySaurav Hathi

MCQ Test C/C++: Arrays

Q1:

Which of the following is correct declaration of array in C/C++?

Tags:
Section:
Core Programming
Options:
Q2:

In C/C++, what will be the index number of the last element of an array with 9 elements?

Tags:
Section:
Core Programming
Options:
Q3:

What is an array in C/C++?

Tags:
Section:
Core Programming
Options:
Q4:

Which of the following accesses the seventh element stored in a C array?

Tags:
Section:
Core Programming
Options:
Q5:

Which of the following gives the memory address of the first element in array in C/C++?

Tags:
Section:
Core Programming
Options:
Q6:

What will be the output of this C++ program?

#include<iostream>

using namespace std;

int array1[] = {1200, 200, 2300, 1230, 1543};

int array2[] = {12, 14, 16, 18, 20};

int temp, result = 0;

int main()

{

for (temp = 0; temp < 5; temp++)

{

result += array1[temp];

}

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

{

result += array2[temp];

}

cout << result;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q7:

What will be the output of the this C++ program?

#include <iostream>

using namespace std;

int main ()

{

int array[] = {0, 2, 4, 6, 7, 5, 3};

int n, result = 0;

for (n = 0; n < 8; n++) {

result += array[n];

}

cout << result;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q8:

What will be the output of below C++ program?

#include <iostream>

using namespace std;

int main()

{

int a = 5, b = 10, c = 15;

int arr[3] = {&a, &b, &c};

cout << *arr[*arr[1] - 8];

return 0;

}

Tags:
Section:
Core Programming
Options:
Q9:

What will be the output of this C++ program?

#include <iostream>

using namespace std;

int main()

{

int array[] = {10, 20, 30};

cout << -2[array];

return 0;

}

Tags:
Section:
Core Programming
Options:
Q10:

How to create a dynamic array of pointers (to integers) of size 10 using new in C++?

Tags:
Section:
Core Programming
Options:
Q11:

Which is correct way to initialize array in C/C++?

Tags:
Section:
Core Programming
Options:
Q12:

What will be the output of this C program ?

#include<stdio.h>

int main()

{

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

int i, j, m;   

i = ++a[1];   //s1

j = a[1]++;    //s2

m = a[i++];    //s3

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

}

Tags:
Section:
Core Programming
Options:
Q13:

What will be the output of following C code?

#include <stdio.h>
int main(void)
{
  char p;
  char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
  p = (buf + 1)[5];
  printf("%d", p);
  return 0;
}

 

Tags:
ct02
Section:
Core Programming
Options:
Q14:

In C/C++ ,array elements are always stored in ________ memory locations.

Tags:
Section:
Core Programming
Options:
Q15:

Which of the following operations cannot be performed on an array arr in C/C++?

I.  ++arr

II. arr+1

III. arr++

IV. arr*2

Tags:
Section:
Core Programming
Options:
Q16:

What is the maximum number of dimensions an array in C can have?

Tags:
Section:
Core Programming
Options:
Q17:

In C/C++, we need to explicitly write size of an array, when _________________

Tags:
Section:
Core Programming
Options:
Q18:

What will be printed after execution of the following C code?

#include<stdio.h>

int main()

{

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

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

}

Tags:
Section:
Core Programming
Options:
Q19:

What will be the output of the following C code?

#include<stdio.h>
int main()
{
  int a[10];
  printf("%d %d", a[-1], a[12]);
}

 

Tags:
IN01
Section:
Core Programming
Options:
Q20:

When we pass array name as the argument in a function, what exactly is passed to the function in C/C++?

Tags:
Section:
Core Programming
Options:
Q21:

What will be the output of this C program if the array begins at 65472 and each integer occupies 2 bytes?

#include<stdio.h>

int main()

{

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

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

}

Tags:
Section:
Core Programming
Options:
Q22:

What will be the output of this C program ?

#include<stdio.h>

int main()

{

float arr[ ] = {12.4, 2.3, 4.5, 6.7};

printf("%d", sizeof(arr)/sizeof(arr[0]));

}

Tags:
Section:
Core Programming
Options: