ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int countOccurrences(const char *str, char target) {
int count = 0;
while (*str) {
if (*str == target) count++;
str++;
}
return count;
}
int main(void) {
printf("%d", countOccurrences("mississippi", 's'));
}- A. 0
- B. 4
- C. 2
- D. 3
Correct answer: B. 4
"mississippi" contains the letter 's' four times (positions 2,3,5,6: m-i-s-s-i-s-s-i-p-p-i), so the loop counts 4.
More C Programming questions
- What is printed? c int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main(void) { printf("%d", gcd(48, 18)); }
- What is printed? c int isPalindrome(const char s, int left, int right) { if (left >= right) return 1; if (s[left] != s[right]) return 0…
- What is printed? c int f(int n) { if (n == 0) return 0; printf("%d ", n % 10); return f(n / 10); } int main(void) { f(4567); }
- What is printed? c void printPattern(int n) { if (n == 0) return; printPattern(n - 1); for (int i = 0; i < n; i++) printf(""); printf("…
- What is printed? c int f(int n) { if (n == 0) return 1; int a = f(n - 1); return a n; } int main(void) { long long result = 1; for (int i…
- What happens? c struct Node { int data; struct Node next; }; struct Node createNode(int val) { struct Node n; n.data = val; n.next = NULL…