Arrays&Strings Quiz Solution
Arrays&Strings Quiz Solution
com
3)Arrays and Strings
1)
Output:20.
Explanation:Notice size between brackets of array.
…………………………………………………………………………………………………………………………………..
5) assume double=8 byte ,int=2 byte,char=1byte .
Output:4.
Explanation:!a will convert to int so int+char=int(2 Bytes), so size of array is 2*2=4Bytes.
…………………………………………………………………………………………………………………………………..
6)
Output:Morning.
Explanation:it skips the first 5 characters and print the given string.
…………………………………………………………………………………………………………………………………..
7)
Output:6.
Explanation: count number of characters until null terminator.
…………………………………………………………………………………………………………………………………..
10)
Output: 0
Explanation: if two strings is equal so strcmp return zero.
…………………………………………………………………………………………………………………………………..
11)
Output:5
Explanation:
The function strlen returns the number of characters int the given string
Therefore, strlen(str) becomes strlen("India") contains 5 characters. A string
'is a collection of characters terminated by '\0
"The output of the program is "5
…………………………………………………………………………………………………………………………………..
14)
Which of the following function is more appropriate for reading in a multi-word string?
Output: gets().
Explanation: to read multi-word we use gets() or fgets(), fgets is safer than gets.
…………………………………………………………………………………………………………………………………..
16)
Output:3,2,15.
Explanation: Step 1: 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
.Step 2: int i, j, m; The variable i,j,m are declared as an integer type
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
.Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by
)1(i++ means 2++ so i=3
Step 6: 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
…………………………………………………………………………………………………………………………………..
17)
Output: 10.
Explanation:0[arr]=arr[0].(later in pointer).
18)
What will be the output of the following program in 16 bit platform assuming that 1022 is
memory address of the string "Hello1" ?
Output: A.
Explanation: Step 1: char p[] = "%d\n"; The variable p is declared as an array
of characters and initialized with string "%d"
Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'.
So array p becomes "%c"
Step 3: printf(p, 65); becomes printf("%c", 65),Therefore it prints the ASCII
'value of 65. The output is 'A
…………………………………………………………………………………………………………………………………..
20)
Output :India.
Explanation:str will print till found null terminated('\0').
21)
Output: Unequal.
Explanation: Step 1: char str1[] = "Hello"; The variable str1 is declared as an array of characters
.and initialized with a string "Hello"
Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters and
initialized with a string "Hello"
.We have use strcmp(s1,s2) function to compare strings
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both
.variable is not same. Hence the if condition is failed
Step 4: At the else part it prints "Unequal"
………………………………………………………………………………………………………………………………….
24)
Output: The program may crash if some important data gets overwritten .
Explanation: If the index of the array size is exceeded, the program will crash. Hence "option c" is
the correct answer. But the modern compilers will take care of this kind of errors .
Since C is a compiler dependent language, it may give different outputs at
.different platforms. We have given the Turbo-C Compiler (Windows) output
Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC
.Compiler), you will understand the difference better
………………………………………………………………………………………………………………………………….
25)Assume that int is 2 Bytes.
Output: 18 0 5.
Explanation: we have 3 rows and 3 cols so array size is 3*3*sizeof(int)=18,
arr[0][2]=0(the compiler put it) and arr[1][2]=5.
………………………………………………………………………………………………………………………………….
26)
Output:3 8 4 9.
………………………………………………………………………………………………………………………………….
28)
Output:9.
Explanation:(buff+1)[5]=buff[6](later in pointers).
………………………………………………………………………………………………………………………………….
31)
Output:Sequential.
………………………………………………………………………………………………………………………………….
32)
Output:India.
Explanation: printf("India", "BIX\n"); It prints "India". Because ,(comma) operator has
Left to Right associativity. After printing "India", the statement got terminated .
33)
The library function used to find the last occurrence of a character in a string is ?
Output: strrchr().
Explanation: Declaration: char *strrchr(const char *s, int c);
int main(void)
if (ptr)
else
return 0;
………………………………………………………………………………………………………………………………….
34)
Output:5.
36)
Output:e.
Explanation: consider str="abcdefgh", and we want to print str[4], so will print
e.
………………………………………………………………………………………………………………………………….
37)
Output: 0 0 \n 1 1 \n 2 2 \n 3 3\n 4 4.
Explanation: comma here is separator so condition will be b<5.
39)
Output: Answer A.
………………………………………………………………………………………………………………………………….
40)
Output: 0 0.
Explanation:the compiler will initialize the rest of elements
by zeros.