C-Array Questions and Answers
C-Array Questions and Answers
11. The function strstr () returns
- Length of the initial substring
- Pointer to the first occurrence of the string
- Pointer to the next token in the string
- Pointer to the last occurrence of the string.
12. Which of the following is/are wrong ?
int a,b[5], c[3]
I. a=b[2];
II. b[3]=a;
III. b[1]=c[2];
IV. C[0]=B[2];
int a,b[5], c[3]
I. a=b[2];
II. b[3]=a;
III. b[1]=c[2];
IV. C[0]=B[2];
- only II
- II & III
- III & IV
- None of the above
13. Find the output
void main()
{ int a[ ] ={1, 2, 3, 4, 5}, k=1;
while (k<=5)
{
printf("%d", k[a-1]);
k++;
}
}
void main()
{ int a[ ] ={1, 2, 3, 4, 5}, k=1;
while (k<=5)
{
printf("%d", k[a-1]);
k++;
}
}
- 5 4 3 2 1
- 1 2 3 4 5
- Routime error
- Compilation error
14. How to measure total size of an integer array ?
- 2 * array size
- sezeof(int)*array size
- 4 * array size
- None of these
15. Which of the following is/are false regarding array ?
I. Array index starts from -1.
II. Array elements are stored in contiguous memory location.
III. The size of the array should be mentioned while declaraing.
IV. Array elements can be accessed using the inded of array
I. Array index starts from -1.
II. Array elements are stored in contiguous memory location.
III. The size of the array should be mentioned while declaraing.
IV. Array elements can be accessed using the inded of array
- only I
- Only III
- III & IV
- I &III
16. What heppens when subscript used for an array exceeds the array size ?
- Compiler gives an error message
- Simply placed excess data outside thearray
- Simply placed excess data on top of other data or on the program itself.
- Memory dump
17. Find the output.
void main ()
{
static int a[ ]={1 2, 3, 4, 5};
int i;
for (i=0; i<5; i++)
{
*(a+i)=a[i] + i[a];
printf(%d", * (i+a));
}
void main ()
{
static int a[ ]={1 2, 3, 4, 5};
int i;
for (i=0; i<5; i++)
{
*(a+i)=a[i] + i[a];
printf(%d", * (i+a));
}
- 2 4 6 8 10
- 1 3 5 7 9
- Expression syntax error
18. Find the output
void main ( )
{
int a[] ={1, 2, 3, 4, 5}, i;
for (i=0; i<5; i++)
{
if (i<3);
printf("%d",a[i]);
else
printf("hi");
}
}
void main ( )
{
int a[] ={1, 2, 3, 4, 5}, i;
for (i=0; i<5; i++)
{
if (i<3);
printf("%d",a[i]);
else
printf("hi");
}
}
- 123hihi
- hahi
- 12345
- Compilation error
19. The array a[j][k] is equivalent to
- ((base type*)a+(j*row length)+k)
- *((base type*)a+(j*row length)+k)
- *(*((base type*)a+(j*row length)))+k)
- None of these
20. Find the output
void main ( )
{
int a [ ] = {4, 5, 6, 7, 8}, i, *p;
for (p=a+4, i=2; i<=4; i++)
printf ("%d",p[-i]);
}
void main ( )
{
int a [ ] = {4, 5, 6, 7, 8}, i, *p;
for (p=a+4, i=2; i<=4; i++)
printf ("%d",p[-i]);
}
- Compilation error
- 6 5 4
- 8 7 6 5 4
- 6 7 8