Arrays And Strings - Study Mode
[#96] What does the following C code do? int iscntrl( int c)
Correct Answer
(C) tests for any control character
[#97] What will the following C code do? char * strrchr(const char *s, int c )
char ch = c
char *sc
for(sc = NULL
++s)
if(*s == ch)
SC = 9
i f (*s =='O' )
return (( char *) s)
Correct Answer
(A) find last occurrence of c in char s[ ].
[#98] What is right way to Initialize array?
Correct Answer
(A) int num[6] = { 2, 4, 12, 5, 45, 5 }
Explanation
Solution: option (B), (C) and (D) are incorrect because array declaration syntax is wrong. Only square brackets([]) must be used for declaring an array.
[#99] What will be the output of the program? #include<stdio.h>
void main()
{
int a[5] = {5, 1, 15, 20, 25}
int i, j, m
i = ++a[1]
j = a[1]++
m = a[i++]
printf("%d, %d, %d", i, j, m)
}
Correct Answer
(A) 3, 2, 15
Explanation
Solution: >> int a[5] = {5, 1, 15, 20, 25}
The variable arr is declared as an integer array with a size of 5 and it is initialized to a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25. >> int i, j, m
The variable i, j, m are declared as an integer type. >> i = ++a[1]
becomes i = ++1
Hence i = 2 and a[1] = 2 >> j = a[1]++
becomes j = 2++
Hence j = 2 and a[1] = 3. >> m = a[i++]
becomes m = a[2]
Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3) >> printf("%d, %d, %d", i, j, m)
It prints the value of the variables i, j, m Hence the output of the program is 3, 2, 15.
[#100] What will be the output of following program 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
}
Correct Answer
(C) 9
Explanation
Solution: x [ i ] is equivalent to *( x + i ) , so ( buf + 1 )[ 5 ] is *( buf + 1 + 5 ) , i.e. buf [ 6 ] .