ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "hello";
char *p = strchr(s, 'l');
printf("%ld", (long)(p - s));
}- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
strchr returns a pointer to the first l, which is at index 2, so the pointer difference is 2.
More C Programming questions
- How many moves does this recursive Towers of Hanoi program make for 4 disks? Compute with the program. c #include <stdio.h> int moves = 0…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t x = 0x96; uint8t r = (uint8t)((x << 3) | (x >> 5))…
- What is printed? Assume signed char is 8 bits, two's complement. c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { long long x = (const long long )a, y =…
- What is printed? c #include <stdio.h> int calls = 0; int g(int a, int b) { calls++; return b ? g(b, a % b) : a; } int main(void) { int r =…
- How many ways are there to climb 20 steps taking 1 or 2 at a time? Compute with this exponential recursion. c #include <stdio.h> long long…