...
Question 17304 – NTA UGC NET Dec 2023 Paper-1
January 8, 2024
Question 15318 – DSSSB PGT 2021
January 8, 2024
Question 17304 – NTA UGC NET Dec 2023 Paper-1
January 8, 2024
Question 15318 – DSSSB PGT 2021
January 8, 2024

Question 11089 – Programming

The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s.

int anagram (char *a, char *b) {
     int count [128], j;
     for (j = 0;  j < 128; j++) count[j] = 0;
     j = 0;
     while (a[j] && b[j]) {
       A;
       B;
}
for (j = 0; j < 128; j++) if (count [j]) return 0;
return 1;
} 

Choose the correct alternative for statements A and B.

Correct Answer: D

Question 1 Explanation: 
A: Increments the count by 1 at each index that is equal to the ASCII value of the alphabet, it is pointing at.
B: Decrements the count by 1 at each index that is equal to the ASCII value of the alphabet it is pointing at. Also it increments the loop counter for next iteration.
If one string is permutation of other, there would have been equal increments and decrements at each index of array, and so count should contain zero at each index, that is what the loop checks at last and if any non-zero elements is found, it returns 0 indicating that strings are not anagram to each other.
A
A : count [a[j]]++ and B : count[b[j]]–
B
A : count [a[j]]++ and B : count[b[j]]++
C
A : count [a[j++]]++ and B : count[b[j]]–
D
A : count [a[j]]++and B : count[b[j++]]–
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!