C Language - Arrays

You Are Here :: Home > C Language > Arrays - General Questions

 
55.

What will be the output of the program in Turb C (under DOS)?

#include
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}

A. 1, 2, 3, 4, 5, B. Garbage value, 1, 2, 3, 4,
C. 0, 1, 2, 3, 4, D. 2, 3, 4, 5, 6,




56.

The following code fragment is intended to find the smallest value in arr [0] ... arr [n-1].

//Precondition: arr [0] ... arr [n-1] initialized with integers.
// arr is an array, arr.length = n
//Postcondition: min = smallest value in arr [0] ...arr [n-1]
int min = arr [0];
int i = 1;
while (i < n)
{
i++;
if (arr [i] < min)
min = arr [i] ;
}
This code is incorrect. For the segment to work as intended, which of the following modifications could be made?
I Change the line
int i = 1 ;
to
int i = 0 ;
Make no other changes
II Change the body of the while loop to
{
if (arr [i] < min)
min = arr [i] ;
i++;
}
Make no other changes.
III Change the test for the while loop as follows: div>while (i <= n)
Make no other changes.

A. I only B. II only
C. III only D. I and II only




57.

You may asume that array arr1 contains elements that arr1 [0], arr1 [1],..., arr1 [N-1] , where N = arr1. length.

int count = 0 ;
for (int i =0; i< N; i++)
if (arr1 [i] != 0)
{
arr1[count] = arr1[i] ;
count ++;
}
int [] arr2 = new int [count] ;
for (int i=0 ; i
arr2[i] = arr1[i];
If array arr1 initially contains the elements 0, 6, 0, 4, 0, 0, 2 in this order, what will arr2 contain refer execution of the code segement?

A. 6, 4, 2 B. 6, 4, 4
C. 0, 6, 0 D. 6, 2, 2




58.

What will be the output of the program ?

#include
int main()
{
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
}

A. 1 B. 10
C. 0 D. 6




59.

You may asume that array arr1 contains elements that arr1 [0], arr1 [1],..., arr1 [N-1] , where N = arr1. length.

int count = 0 ;
for (int i =0; i< N; i++)
if (arr1 [i] != 0)
{
arr1[count] = arr1[i] ;
count ++;
}
int [] arr2 = new int [count] ;
for (int i=0 ; i
arr2[i] = arr1[i];
The algorithm has run time

A. O (N log N) B. O (N)
C. O (1) D. O (log N)




60.

Consider this program segment

for (int i =2; i<=k; i++)
if (arr [i]
System. out. print ("SMALL");
What is the maximum numbere of times that SMALL can be printed?

A. 0 B. 1
C. k-1 D. k-2




« previous

10

11

next »

 
 
 



© 2013 freshersindia.in ® | Copyrights | Terms & Conditions
   Designed by Freshers India
Catch Us on